开发者

by jquery, after row click handler return first td attribute in clicked row

$('#myTable tr:last'); i get a tr content(without tr tag). how can i get tr attribute? I can't. then tried to get attribute er from first td on clicked row. and now same problem.

$('#myTable tr').click(function() {
   var State = $(this).find("td:first-child").attr("er"); // this开发者_StackOverflow中文版 code is false
   alert(State);
});

My HTML

             <table width="600px" cellspacing="0" border="1" id="myTable">
                <tr>
                    <th>
                        ...
                    </th>
                    <th>
                        ...
                    </th>
                    <th>
                        ...
                    </th>
                    <th>
                        ...
                    </th>
                    <th>
                        ...
                    </th>
                    <th>
                    !
                    </th>
                </tr>
                <tr bgcolor="#484848">
                    <td width="152px;" class="textField" er="editable">
                        <input type="text" value="" />
                    </td>
                    <td width="350px;">
                        <textarea cols="40" rows="3"></textarea>
                    </td>
                    <td>
                        <select disabled="disabled">
                            //options
                        </select>
                    </td>
                    <td width="152px;">
                        <input type="text" />
                    </td>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>
                    </td>
                </tr>
            </table>


This works fine for me

$("#example tr:last").click(function() {
    console.log($(this).find("td:first"));
});

$("#example tr:last").click(function(){
    console.log($(this).attr("class"));
});

First event prints the first td in the last tr on click on the last tr.

Second event prints the class attribute in the last tr on click on the last tr.


Shouldn't it be $(this).find("td:first") ?


You can get the tr attribute by using $(this).parent()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜