How Can I concatenate a parameter string in javascript function on string in appended html?

前端 未结 5 1418
借酒劲吻你
借酒劲吻你 2021-01-17 04:45

This is my code for html

 

Then I append an inpunt to #content:

 $( document ).ready         


        
相关标签:
5条回答
  • 2021-01-17 04:59

    The second input should be something like that.

    '<input type="submit" name="submit_answers" value="Submit" onclick="getValue2('+parameter+')" >'
    
    0 讨论(0)
  • 2021-01-17 05:06

    You can try this:

    '<input type="submit" name="submit_answers" value="Submit" onclick="getValue2(\'' + parameter + '\');" >'
    
    0 讨论(0)
  • 2021-01-17 05:07

    I think you probably just weren't separating correctly. Try this exemple:

    onclick="mySup(\''+json.id+'\',\''+json.description+'\');"

    0 讨论(0)
  • 2021-01-17 05:10

    You could do this:

    onclick="getValue2("' + parameter + '")"
    

    But something like this would be better:

    var $div = $('<div><p>click the botton</p></div>');
    var $button = $('<input type="submit" name="submit_answers" value="Submit">')
        .data('parameter', parameter)
        .click(function () {
            getValue2($(this).data('parameter'));
        }).appendTo($div);
    
    $("#content").append($div);
    
    0 讨论(0)
  • 2021-01-17 05:20

    Try this :

    $( document ).ready(function() {
    // Handler for .ready() called.
       var parameter = "<p>Hola new</p>";
       $("#content").append('<div><p>click the botton</p>'+
                     '<input type="submit" name="submit_answers" value="Submit" onclick="getValue();" >'+  
                     '<input type="submit" name="submit_answers" value="Submit" onclick="getValue2(\''+parameter+'\');" >'+                        
                     '</div>');
    });
    
    0 讨论(0)
提交回复
热议问题