Pass multiple values with onClick in HTML link

后端 未结 8 1582
眼角桃花
眼角桃花 2021-02-04 03:50

Hi Im trying to pass multiple values with the HTML onclick function. Im using Javascript to create the Table

var user = element.UserName;
var valuationId = eleme         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 04:07

    If valuationId and user are JavaScript variables, and the source code is plain static HTML, not generated by any means, you should try:

    Re-Assign
    

    If they are generated from PHP, and they contain string values, use the escaped quoting around each variables like this:

    Re-Assign';
    ?>
    

    The logic is similar to the updated code in the question, which generates code using JavaScript (maybe using jQuery?): don't forget to apply the escaped quotes to each variable:

    var user = element.UserName;
    var valuationId = element.ValuationId;
    $('#ValuationAssignedTable').append(' Re-Assign   ');
    

    The moral of the story is

    'someString(\''+'otherString'+','+'yetAnotherString'+'\')'
    

    Will get evaluated as:

    someString('otherString,yetAnotherString');
    

    Whereas you would need:

    someString('otherString','yetAnotherString');
    

提交回复
热议问题