zoukankan      html  css  js  c++  java
  • JQuery 获取父元素方法

    ---恢复内容开始---

    <tr class="removerow" style="">
                    <td>
                        <input type="submit" name="ListView1$ctrl0$DeleteButton" value="删除" id="ListView1_DeleteButton_0" />
                        <input type="submit" name="ListView1$ctrl0$EditButton" value="编辑" id="ListView1_EditButton_0" />
                        <input type="button" isRemoveRow="true" value="无刷新删除" curId='1' />
                    </td>
                    <td>
                        <span id="ListView1_IdLabel_0">1</span>
                    </td>
                    <td>
                        <span id="ListView1_PostDateLabel_0">2008/8/8 0:00:00</span>
                    </td>
                    <td>
                        <span id="ListView1_MsgLabel_0">好啊</span>
                    </td>
                </tr>
            
                    
                <tr class="removerow" style="">
                    <td>
                        <input type="submit" name="ListView1$ctrl1$DeleteButton" value="删除" id="ListView1_DeleteButton_1" />
                        <input type="submit" name="ListView1$ctrl1$EditButton" value="编辑" id="ListView1_EditButton_1" />
                        <input type="button" isRemoveRow="true" value="无刷新删除" curId='2' />
                    </td>
                    <td>
                        <span id="ListView1_IdLabel_1">2</span>
                    </td>
                    <td>
                        <span id="ListView1_PostDateLabel_1">2008/8/8 0:00:00</span>
                    </td>
                    <td>
                        <span id="ListView1_MsgLabel_1">沙发</span>
                    </td>
                </tr>

    查找父元素tr,将该元素删除。

    $("input[curId=" + id + "]").parent().parent().remove();  //父元素的父元素 找到tr

    $("input[curId=" + id + "]").parents("tr")[0].remove();  // 祖先元素 找到tr HTMLTableRowElement

    $("input[curId=" + id + "]").parents(".removerow").remove(); //祖先元素 样式筛选

    使用parents("tr") 通过tr元素查找,会返回2条数据,parents("tr").html() 能正常获取该行,如果html("") 无法正常修改。

    删除该行tr,必须加parents("tr")[0].remove(); 才行。但是parents("tr")[0].html("")也无法正常修改, 不知道为什么会这样!

    看来还是通过添加样式parents(".removerow") 操作方便些。

  • 相关阅读:
    Nginx的配置详解
    马拉车算法
    C++ 智能指针(shared_ptr/weak_ptr)原理分析
    大小端(内存、寄存器、CPU)
    printf函数输出字符串乱码问题
    ArcGIS中应用Expressions标注(Label)之二—使用外部数据库中数据标注要素
    Cisco Aironet ap3g1/ap3g2 8.5版本胖AP固件网页配置教程
    Golang mapstructure
    NDB 和 InnoDB 的不同
    高质量:Makefile
  • 原文地址:https://www.cnblogs.com/han1982/p/3342060.html
Copyright © 2011-2022 走看看