【问题标题】:Getting a specific value from a table created in Code Behind从代码隐藏中创建的表中获取特定值
【发布时间】:2013-06-29 19:46:32
【问题描述】:

我正在尝试从运行时在后面的代码中创建的表中检索特定值。 使用 jquery。

sb.Append("<tr><td>");
                sb.Append(prodCode);
                sb.Append("</td>");


                sb.Append("<td>");
                sb.Append("<input type='checkbox' name='chkBestSeller' value='Best Seller' style='font-size:x-small;'");
                sb.Append("<input type='hidden' name='prodCodeBestSeller' value='" + prodCode + "'");
                sb.Append("</td>");
Products.InnerHtml = sb.ToString();

这是我的 jquery 函数。

$(document).on("click", "input[name='chkBestSeller']", function () {
var code = $(this).parent().find("input[name='prodCodeBestSeller']").val();
alert(code);

});

我的感觉是它应该可以工作,但它会带回一个“未定义”的值。

如何实现在特定行检索代码值

【问题讨论】:

  • 你没有用&gt;关闭你的输入......

标签: c# jquery webforms code-behind


【解决方案1】:

试试这个

$("input[name='chkBestSeller']").click( function () {
var code = $(this).closest('tr').find("input[name='prodCodeBestSeller']").val();
alert(code);
});

【讨论】:

    【解决方案2】:
    $(document).on("click", "input[name='chkBestSeller']" ...
    

    this指的是被点击的元素,即input[name='chkBestSeller']。

    在你的情况下,你可以得到隐藏字段的值

    $(this).next().val()
    

    【讨论】:

      猜你喜欢
      • 2014-04-10
      • 2012-12-28
      • 2019-11-23
      • 2013-03-17
      • 1970-01-01
      • 2020-07-29
      • 2013-07-16
      • 1970-01-01
      • 2012-01-20
      相关资源
      最近更新 更多