基本上,我在下面有一个非常简单的代码。我需要改变数额和电子邮件每次如果有人改变这些。
更新:
多亏了@ellipsis。你的版本几乎是理想的,除了发送数据。
我需要将数据(html)从function()传输到document.write('\x3C script type=“text/javascript”'+html+'>\x3C/script>');

var amount = '';
    var email = '';
    var html='';

    $(document).ready(function() {
      $("#amount").keyup(function() {
        amount = $('#amount').val();
        email = $('#email').val();

        var key = '123345';
        var hash = '' //sha256(email+amount+key); // dynamic email & amount

        html = 'src="test.html" '+'amount="' + amount + '" '+'email="' + email + '" '+'hash="' + hash + '" ';

        $('.check').text('\x3Cscript type="text/javascript" '+html+'>\x3C/script>');

      });

    });
        // I need to add the 'html' below
       document.write('\x3Cscript type="text/javascript" '+html+'>\x3C/script>');

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<form action="test.html?" method="get">
    <button id="button">Send it</button>
    <input type="text" id="amount" >
    <input type="text" id="email" >
    <p class="check"></p>
</form>

最佳答案

var amount   = '';
var email     ='';

$(document).ready(function(){
  $("#amount").change(function(){
    postRun();
  });
$("#email").change(function(){
    postRun();
  });
});

function postRun(){

    amount   = $('#amount').val();
    email     = $('#email').val();
    var key     = '123345';
    var hash     = sha256(email+amount+key); // dynamic email & amount

    html  = '';
    html +='tamount="'+amount+'" '; // dynamic
    html +='email="'+email+'" '; // dynamic
    html +='hash="'+hash+'" '; // dynamic every time
}

关于jquery - 如果输入值更改,如何动态替换var中的数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54823592/

10-13 07:31
查看更多