0

我想按如下方式访问嵌套中的anchor标签。jquery我想选择每个锚点并在jquery.

<table id="table1">
<tr>
    <th>Tags</th>
    <th>ID</th>
    <th>Batch ID</th>
    <th>Source</th>
    <th>Date</th>
    <th>Details
        <div id="detailsdiv">
         <a href="#" id="default">Default</a>&nbsp;|&nbsp;
         <a href="#" id="wrap">Wrap</a>
        </div>
    </th>
    <th>Account Name</th>
    <th>Col15</th>
    <th>Col16</th>
    <th>Col17</th>
    <th>Col18</th>
  </tr>

4

5 回答 5

3

使用以下方法选择锚标记:

$("table #detailsdiv a")

并使用以下.on()方法应用点击功能:

$("table #detailsdiv a").on("click", function() {
    //use this to select the element that has been clicked
    $(this);        

    //Do click functionality here
});

或者,您也可以.click()直接使用 jQuery 方法:

 $("table #detailsdiv a").click(function() {
     //use this to select the element that has been clicked
     $(this);         

     //Do click functionality here
 });
于 2013-05-21T11:30:03.333 回答
2

尝试这个:

$('#detailsdiv a').click(function(event){

    // Cancel the default action (navigation) of the click.
    event.preventDefault();

    // You can get the id of clicked link
    alert(this.id);

    // Your code goes here..
});
于 2013-05-21T11:32:25.117 回答
1

尝试

  $("#detailsdiv a").click(function() {
            // add function  And
            $(this) // add function for clicked tag
        });
于 2013-05-21T11:34:07.387 回答
0
$('table tr th a').each(function(){
  $(this).click(function(e){
      e.preventDefault();
      //your function here;
  });
});
于 2013-05-21T11:33:03.823 回答
0

哟也可以试试这个:

$('table  #detailsdiv a').click(function(e){
    alert(this.id);
});
于 2013-05-21T11:34:30.847 回答