简体   繁体   English

如何使用Jquery选择特定的嵌套元素

[英]How can I select specific nested element with Jquery

I have this markup 我有这个标记

     <table id="myexample" class="myclass">
     <thead>
     <tr>
     <th><input type="checkbox" value="tableoption1"> Username</th>
     <th> Something </th>
     <th> Something </th>
     <th> Something </th>
     <th> Something </th>
     <th> Something </th>
      <th> Something </th>

     </tr>
     </thead>
     <tbody>
     <tr>
     <td> <input id="user1" type="checkbox" value="tableoption1">  John Smith </a></td>
     <td> Nickname</td>
     <td> Address </td>
     <td> Registerd</td>
     <td>10-10-2014 </td>
     <td>09-11-2014</td>
     <td>03-02-2014</td>
     </tr>
</table>

How can I select with Jquery the input element with id=user1 ? 如何使用Jquery选择id = user1的输入元素?

I have already tried this but doesnt work 我已经尝试过了,但是没有用

 $("#users tbody tr td input").click(function(){ 
      alert ("success");
 });

Any suggestion ? 有什么建议吗?

This should work: 这应该工作:

$('#user1').click(function(){ 
      alert ("success");
 });
$( "#user1" )

试试这个,我认为这就是您要问的。

If you want to control when checkbox is checked: 如果要控制何时选中复选框:

$('#user1').click(function(){ 
    if($(this).is(":checked")){
        alert("checked!");
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM