Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery触发按钮在表中单击td_Javascript_Jquery_Html_Onclick - Fatal编程技术网

Javascript jQuery触发按钮在表中单击td

Javascript jQuery触发按钮在表中单击td,javascript,jquery,html,onclick,Javascript,Jquery,Html,Onclick,我的桌体和tr内有一个按钮: 这是我正在为jquery事件尝试的代码: 但是什么都没发生。。。我在这里做错了什么 $(“#tableProducts tbody tr td”)。单击(函数(){ console.log(this.val()); }); 单元格上没有val()之类的东西 如果按钮ID应该是唯一的,只需执行以下操作: $("#btnSearch").click(function() { // using the unique ID of the button console.

我的桌体和tr内有一个按钮:

这是我正在为jquery事件尝试的代码:

但是什么都没发生。。。我在这里做错了什么

$(“#tableProducts tbody tr td”)。单击(函数(){
console.log(this.val());
});

单元格上没有val()之类的东西

如果按钮ID应该是唯一的,只需执行以下操作:

$("#btnSearch").click(function() { // using the unique ID of the button
  console.log($(this).val());
});
如果按钮在加载后插入,则需要委派。下面是在动态插入完整表时单击表中单元格中任何按钮的代码

$(document).on(“click”,“#tableProducts tbody tr td button.btn”,function(){//any button
log($(this.val());
});

产品名称
销售额
价格
@ViewBag.Products[i].SaleNumber
$@ViewBag.Products[i].售价
@ViewBag.Products[i].SaleNumber
$@ViewBag.Products[i].售价

单元格上没有val()之类的东西

如果按钮ID应该是唯一的,只需执行以下操作:

$("#btnSearch").click(function() { // using the unique ID of the button
  console.log($(this).val());
});
如果按钮在加载后插入,则需要委派。下面是在动态插入完整表时单击表中单元格中任何按钮的代码

$(document).on(“click”,“#tableProducts tbody tr td button.btn”,function(){//any button
log($(this.val());
});

产品名称
销售额
价格
@ViewBag.Products[i].SaleNumber
$@ViewBag.Products[i].售价
@ViewBag.Products[i].SaleNumber
$@ViewBag.Products[i].售价
试试这个

 <script>

 $("#tableProducts tbody tr td button").click(function () {
  console.log($(this).val());
 });

 </script>

$(“#tableProducts tbody tr td按钮”)。单击(函数(){
log($(this.val());
});
试试这个

 <script>

 $("#tableProducts tbody tr td button").click(function () {
  console.log($(this).val());
 });

 </script>

$(“#tableProducts tbody tr td按钮”)。单击(函数(){
log($(this.val());
});

是的,如果您在此处运行时看到上面的HTML,它们就会显示出来。如果您没有唯一的按钮ID,那么该示例将无法在您的代码中运行一个以上的时间cell@mplugjan我已经用表格HTML编辑了我的问题,你能看一下吗?我尝试了两种解决方案,没有一种会因为某种原因触发事件…哦,我忘了!!此表是在对服务器执行post操作后生成的,然后服务器返回整个HTML,并在此之后更新HTML。。我想这就是问题所在,我将编辑我的问题来说明我的意思,如果你有上面的HTML,我将更新以处理动态插入,正如你在这里运行它们时看到的那样。如果您没有唯一的按钮ID,那么该示例将无法在您的代码中运行一个以上的时间cell@mplugjan我已经用表格HTML编辑了我的问题,你能看一下吗?我尝试了两种解决方案,没有一种会因为某种原因触发事件…哦,我忘了!!此表是在对服务器执行post操作后生成的,然后服务器返回整个HTML,并在此之后更新HTML。。我想这就是问题所在,我将编辑我的问题以显示我的意思,并更新以处理动态插入