Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery从表的最后一个tr获取属性_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用jquery从表的最后一个tr获取属性

Javascript 使用jquery从表的最后一个tr获取属性,javascript,jquery,html,Javascript,Jquery,Html,在这个jquery脚本中有点卡住了。我想在选中复选框的tr中获取最后一个td的link属性。 这是HTML <tr> <td><input type="checkbox" name="check" value="happy"></td> <td style="width: 310px; line-height: 14px;" class="fileName <?php echo $my


在这个jquery脚本中有点卡住了。我想在选中复选框的
tr
中获取最后一个
td
link
属性。 这是HTML

      <tr>
          <td><input type="checkbox" name="check" value="happy"></td>
          <td style="width: 310px; line-height: 14px;" class="fileName <?php echo $myClass; ?>" ><div style="width: 310px; overflow: hidden;"><a href="https://abcd.com/<?php echo $info."/".$myinfo['name'];?>" title="<?php echo $myinfo['name'];?>" target="_blank"><?php echo $fileName.'.'.$fileExtension; ?></a></div></td>
           <td style="width: 150px;"><?php echo $fileSize; ?> KB</td>
           <td style="width: 150px;"><?php echo $fileModified; ?></td>
           <td style="width: 150px;">
               <a href="javascript:void(0);" ><span id="" link="https://abcd.com/<?php echo $info."/".$myinfo['name'];?>" title="<?php echo $myinfo['name'];?>" class="shareIcon"></span></a>
               <a href="javascript:void(0);"><span id="deleteIcon" link="<?php echo $myBucket['name'];?>" class="deleteIcon"></span></a>
           </td>
         </tr>

有几个错误:
1) 验证html,不正确地关闭
输入
标记。这导致了以下几点

checked.parent()  //points the body not its actual td
2) 转义字符的正确方法

link="https://abcd.com/<?php echo $info."/".$myinfo['name'];?>"  //WRONG
最后,不需要为了获得最后一个
td
而进行迭代,您可以像这样使用
:last

 $("input[name='check']").on('change',function() {
   var checked = $("input[name='check']:checked");
     console.log(checked.parents('tr')
                           .find('td:last')
                           .find('.shareIcon').attr('link'));
 });

有几个错误:
1) 验证html,不正确地关闭
输入
标记。这导致了以下几点

checked.parent()  //points the body not its actual td
2) 转义字符的正确方法

link="https://abcd.com/<?php echo $info."/".$myinfo['name'];?>"  //WRONG
最后,不需要为了获得最后一个
td
而进行迭代,您可以像这样使用
:last

 $("input[name='check']").on('change',function() {
   var checked = $("input[name='check']:checked");
     console.log(checked.parents('tr')
                           .find('td:last')
                           .find('.shareIcon').attr('link'));
 });

有几个错误:
1) 验证html,不正确地关闭
输入
标记。这导致了以下几点

checked.parent()  //points the body not its actual td
2) 转义字符的正确方法

link="https://abcd.com/<?php echo $info."/".$myinfo['name'];?>"  //WRONG
最后,不需要为了获得最后一个
td
而进行迭代,您可以像这样使用
:last

 $("input[name='check']").on('change',function() {
   var checked = $("input[name='check']:checked");
     console.log(checked.parents('tr')
                           .find('td:last')
                           .find('.shareIcon').attr('link'));
 });

有几个错误:
1) 验证html,不正确地关闭
输入
标记。这导致了以下几点

checked.parent()  //points the body not its actual td
2) 转义字符的正确方法

link="https://abcd.com/<?php echo $info."/".$myinfo['name'];?>"  //WRONG
最后,不需要为了获得最后一个
td
而进行迭代,您可以像这样使用
:last

 $("input[name='check']").on('change',function() {
   var checked = $("input[name='check']:checked");
     console.log(checked.parents('tr')
                           .find('td:last')
                           .find('.shareIcon').attr('link'));
 });
请尝试以下脚本:

 $("input[name='check']").on('change', function () {
     var checked = $("input[name='check']:checked");
     $.each(checked, function () {
         if (checked.length >= 1) {
             $.each(checked.parent().siblings().last().children().children(), function() {
                 console.log($(this).data("link"));
             });
         }
     })
 });
这个HTML:

<table>
    <tr>
        <td>
            <input type="checkbox" name="check" value="happy">
        </td>
        <td style="width: 310px; line-height: 14px;" class="fileName <?php echo $myClass; ?>">
            <div style="width: 310px; overflow: hidden;"><a href="https://abcd.com/areeb" title="areeb" target="_blank">some_file.php</a>

            </div>
        </td>
        <td style="width: 150px;">212KB</td>
        <td style="width: 150px;">some_file.php</td>
        <td style="width: 150px;"> <a href="javascript:void(0);"><span id="" data-link="https://abcd.com/areeb" title="<?php echo $myinfo['name'];?>" class="shareIcon"></span></a>
 <a href="javascript:void(0);"><span id="deleteIcon" data-link="<?php echo $myBucket['name'];?>" class="deleteIcon"></span></a>

        </td>
    </tr>
</table>

请尝试以下脚本:

 $("input[name='check']").on('change', function () {
     var checked = $("input[name='check']:checked");
     $.each(checked, function () {
         if (checked.length >= 1) {
             $.each(checked.parent().siblings().last().children().children(), function() {
                 console.log($(this).data("link"));
             });
         }
     })
 });
这个HTML:

<table>
    <tr>
        <td>
            <input type="checkbox" name="check" value="happy">
        </td>
        <td style="width: 310px; line-height: 14px;" class="fileName <?php echo $myClass; ?>">
            <div style="width: 310px; overflow: hidden;"><a href="https://abcd.com/areeb" title="areeb" target="_blank">some_file.php</a>

            </div>
        </td>
        <td style="width: 150px;">212KB</td>
        <td style="width: 150px;">some_file.php</td>
        <td style="width: 150px;"> <a href="javascript:void(0);"><span id="" data-link="https://abcd.com/areeb" title="<?php echo $myinfo['name'];?>" class="shareIcon"></span></a>
 <a href="javascript:void(0);"><span id="deleteIcon" data-link="<?php echo $myBucket['name'];?>" class="deleteIcon"></span></a>

        </td>
    </tr>
</table>

请尝试以下脚本:

 $("input[name='check']").on('change', function () {
     var checked = $("input[name='check']:checked");
     $.each(checked, function () {
         if (checked.length >= 1) {
             $.each(checked.parent().siblings().last().children().children(), function() {
                 console.log($(this).data("link"));
             });
         }
     })
 });
这个HTML:

<table>
    <tr>
        <td>
            <input type="checkbox" name="check" value="happy">
        </td>
        <td style="width: 310px; line-height: 14px;" class="fileName <?php echo $myClass; ?>">
            <div style="width: 310px; overflow: hidden;"><a href="https://abcd.com/areeb" title="areeb" target="_blank">some_file.php</a>

            </div>
        </td>
        <td style="width: 150px;">212KB</td>
        <td style="width: 150px;">some_file.php</td>
        <td style="width: 150px;"> <a href="javascript:void(0);"><span id="" data-link="https://abcd.com/areeb" title="<?php echo $myinfo['name'];?>" class="shareIcon"></span></a>
 <a href="javascript:void(0);"><span id="deleteIcon" data-link="<?php echo $myBucket['name'];?>" class="deleteIcon"></span></a>

        </td>
    </tr>
</table>

请尝试以下脚本:

 $("input[name='check']").on('change', function () {
     var checked = $("input[name='check']:checked");
     $.each(checked, function () {
         if (checked.length >= 1) {
             $.each(checked.parent().siblings().last().children().children(), function() {
                 console.log($(this).data("link"));
             });
         }
     })
 });
这个HTML:

<table>
    <tr>
        <td>
            <input type="checkbox" name="check" value="happy">
        </td>
        <td style="width: 310px; line-height: 14px;" class="fileName <?php echo $myClass; ?>">
            <div style="width: 310px; overflow: hidden;"><a href="https://abcd.com/areeb" title="areeb" target="_blank">some_file.php</a>

            </div>
        </td>
        <td style="width: 150px;">212KB</td>
        <td style="width: 150px;">some_file.php</td>
        <td style="width: 150px;"> <a href="javascript:void(0);"><span id="" data-link="https://abcd.com/areeb" title="<?php echo $myinfo['name'];?>" class="shareIcon"></span></a>
 <a href="javascript:void(0);"><span id="deleteIcon" data-link="<?php echo $myBucket['name'];?>" class="deleteIcon"></span></a>

        </td>
    </tr>
</table>


为您选中了。长度=1。因此它没有进入内部。我认为这不是问题,因为我得到的值就在那里。我发现的问题是使用
父项
兄弟项
methodoops@MohammadAreebSiddiqui tested无法获得链接属性difference@KousikChowdhury我有多行,我希望它检查多个发送或删除功能时,请进入多个发送或删除功能的内部。长度=1。因此,它不会进入内部。我认为这不是问题,因为我在那里获得了值。我发现的问题是使用
父对象
同级对象
方法oops获取链接属性@MohammadAreebSiddiqui测试不合格difference@KousikChowdhury我有多个行,我希望它进入多个行,因为它是用于多个发送或删除功能将对您更有帮助检查。长度=1。因此它不进入内部。我认为这不是问题,因为我得到的值就在那里。我发现的问题是使用
父级
同级
方法oops@MohammadAreebSiddiqui获取链接属性tested-not-makedifference@KousikChowdhury我有多行,我希望它进入多行,因为它是为多个发送或删除功能将更帮助你检查。长度=1。所以它不去在内部。我认为这不是问题所在,因为我得到的值就在那里。我发现的问题是使用
父级
同级
methodoops@MohammadAreebSiddiqui tested获取link属性不正确difference@KousikChowdhury我有多行,我希望它进入多个,因为它是多行发送或删除功能将更有帮助