【问题标题】:get html value on checkbox click from a table using jquery使用jquery从表中单击复选框获取html值
【发布时间】:2011-11-22 19:48:05
【问题描述】:

我在从数据库获取数据后在页面加载时创建如下动态表

<table border="1" id="tableView">
        <thead>
            <th></th><th>ID</th><th>Name</th><th>Description</th><th>Active</th><th>Release Date</th>
        </thead>

        <tbody>
        <%
        for(int i=0;i<result.size();i++)
        {
            %><tr><td><input class="tablechkbox" type="checkbox"/></td><%
            String[] row=pi.getResults(result,i,params);
            for(int j=0;j<row.length;j++)
            {
                %><td class="viewa"><%out.print(row[j]);%></td><%
            }
            %></tr><%
        } %>
        </tbody>
    </table>

这就是我获取ID 列的方法。请帮我获取任何特定的列

$('#tableView tbody tr').live('click', function (event) {
        if ($('input.tablechkbox', this).is(':checked'))
        {
            alert(this.innerHTMl());
            /*$('.viewa', this).each(function() {
                alert(this.innerHTMl());
            });*/
        }
    });

下面是我的jsp页面截图

【问题讨论】:

  • 您最好发布HTML 代码而不是JSP。你能解释一下你的问题Please help me fetch any specific column吗?
  • @JMax:任何特定列表示“ID、名称、描述、活动、发布日期”中的任何一个

标签: javascript jquery jsp


【解决方案1】:

alert($(this).find("td:eq(1)").html());应该工作

【讨论】:

    【解决方案2】:

    考虑使用 HTML5 数据属性将行 ID 存储在行中(前缀允许您定义“合法”的任意属性):

    String[] row = pi.getResults(result, i, params);
    %>
    <tr data-id="<%=row[0]%>">
        <td><input class="tablechkbox" type="checkbox" /></td>
    

    这样,您可以直接从点击的行中获取 Id:

    $('#tableView tbody tr').live('click', function (event) {
        if ($('input.tablechkbox', this).is(':checked')) {
            var id = $(this).data("id")
    

    您可以在旧版本的 jQuery 中使用 $(this).attr("data-id")。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 2010-11-20
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多