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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM