【问题标题】:How to remove a child element with simple dom html如何使用简单的 dom html 删除子元素
【发布时间】:2016-09-28 10:43:42
【问题描述】:

我想用 子选择器 of PHP Simple HTML DOM 删除这个 html 中的第 4 个,没有 id/class

<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>

【问题讨论】:

  • 你可以使用 jquery 来做这个
  • 只像 PHP Simple HTML DOM

标签: php simple-html-dom


【解决方案1】:

$tr为你正在使用的行,你可以选择下面的孩子:

$fourthTh = $tr->children(4)

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

$tr->removeChild($fourthTh)

【讨论】:

    猜你喜欢
    • 2012-01-03
    • 2015-05-20
    • 1970-01-01
    • 2014-12-07
    • 2014-09-01
    • 1970-01-01
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多