• 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") 操作方便些。

  • 相关阅读:
    Mybatis异常--java.lang.IllegalArgumentException: NO ENUM const class org.apache.ibatis.type.JdbcType.int
    JAVA(IO流)文件复制
    JAVA继承与覆写
    收藏一些是实用的小技巧
    利用JS生成01010101……长度可控的序列
    JS脚本收藏(一些实用的函数)
    利用JavaScript生成随机数字!
    JavaScript自学之数组排序
    前端开发自学之JavaScript——显示当前时间
    Spring Boot Sample 016之spring-boot-error-exception
  • 原文地址:https://www.cnblogs.com/han1982/p/3342060.html
Copyright © 2020-2023  润新知