【问题标题】:PHP Simple HTML DOM Parser display nonePHP 简单 HTML DOM 解析器显示无
【发布时间】:2011-11-19 20:00:44
【问题描述】:

我正在尝试弄清楚如何使用解析器将元素设置为不可见。这是我尝试过的方法,但不幸的是:

$button->style = "display:none";

有什么想法吗?谢谢

【问题讨论】:

  • 只是一些
  • <button> 不是有效的 PHP 类型。 $button 是什么 PHP 类型?
  • 它来自解析器 :) 像这样: $button = $dom->find("button#save]",0);

标签: php domparser


【解决方案1】:

使用set setAttribute方法http://php.net/manual/en/domelement.setattribute.php

$button->setAttribute("style", "display:none");

【讨论】:

    【解决方案2】:

    我不知道你使用的是哪个解析器,但是如果你想隐藏一些 HTML 元素,你需要将style 属性设置为display:none

    因此访问buttonstyle 属性并使用display:none 设置/扩展它。

    根据http://simplehtmldom.sourceforge.net/ 给出的参考(如果这是您正在使用的组件),应该这样做:

    $dom->find("button[id=save]",0)->style = 'display:none';
    

    【讨论】:

      【解决方案3】:

      这是我的解决方案

      $html->find('div[style=display:none]')
      

      【讨论】:

        猜你喜欢
        • 2012-01-17
        • 1970-01-01
        • 1970-01-01
        • 2013-12-25
        • 2016-07-30
        • 2014-01-15
        • 2011-08-27
        • 2018-03-05
        相关资源
        最近更新 更多