开发者

get html value on checkbox click from a table using jquery

I am creating a dynamic table like below on开发者_如何学编程 page load after fetching data from database

<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>

This is what I am doing to fetch ID column. Please help me fetch any specific column

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

Below is my jsp page screenshot

get html value on checkbox click from a table using jquery


alert($(this).find("td:eq(1)").html()); should work


Consider storing the row Id in your row using an HTML5 data- attribute (the prefix allows you to define arbitrary attributes that are "legal"):

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

That way, you can grab the Id directly from the clicked row:

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

You can use $(this).attr("data-id") in older versions of jQuery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜