簡體   English   中英

如何使用簡單的 dom html 刪除子元素

[英]How to remove a child element with simple dom html

我想使用沒有 id/class 的PHP Simple HTML DOM 的子選擇器刪除此 html 中的第 4 個

<tr>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
</tr>

$tr作為您正在使用的行,您可以使用以下內容選擇子項:

$fourthTh = $tr->children(4)

然后,您可以在父元素上使用DOMNode::removeChild()刪除子元素:

$tr->removeChild($fourthTh)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM