HTML 按钮点击函数无法使用 jQuery 变量作为参数


success: function(jsonresponse) {
    data = JSON.stringify(jsonresponse);
  $.each(JSON.parse(data), function (index, item) {
    var Id=item.id;
    var JobId=item.JobId;
 var eachrow = "<tr>"
             + "<td>" + item.id + "</td>"
             + "<td>" + item.JobId + "</td>"
             + "<td>" + item.UserId + "</td>"
             + "<td>" + item.updatedAt + "</td>"
             + "<td>" + "<button onclick='myFunction(JobId,Id, "accepted")' class='btn btn-success btn-block'>Reject</button>" + "</td>"
             + "<td>" + "<button onclick='myFunction(JobId,Id, "rejected")' class='btn btn-success btn-block'>Reject</button>" + "</td>"
             + "</tr>";
 $('#tbody2').append(eachrow);
 });
},

myFuntion(JobId,Id,\"accept\"(不能将变量作为参数,但是当手动添加时,该函数可以工作,就像myFuntion(1,3,\"accepted\">

(。

问题:您没有在HTML代码中连接JobIdId

溶液:在HTML代码中正确连接JobIdId变量,您将很高兴:

success: function(jsonresponse) {
    data = JSON.stringify(jsonresponse);
  $.each(JSON.parse(data), function (index, item) {
    var Id=item.id;
    var JobId=item.JobId;
 var eachrow = "<tr>"
             + "<td>" + item.id + "</td>"
             + "<td>" + item.JobId + "</td>"
             + "<td>" + item.UserId + "</td>"
             + "<td>" + item.updatedAt + "</td>"
             + "<td>" + "<button onclick='myFunction("+JobId+","+Id+", "accepted")' class='btn btn-success btn-block'>Reject</button>" + "</td>"
             + "<td>" + "<button onclick='myFunction("+JobId+","+Id+", "rejected")' class='btn btn-success btn-block'>Reject</button>" + "</td>"
             + "</tr>";
 $('#tbody2').append(eachrow);
 });
},

相关内容

  • 没有找到相关文章

最新更新