<分区>
我有一个 HTML 字符串。如何找到带有标签 #test 的 div 并向其添加样式属性,例如 style="page-break-inside:avoid;"
?
最佳答案
简单你可以使用PHP Html parser . 例如听到:
$dom = new Dom;
$dom->load('<div id="test"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');
$div = $dom->find("#test");
$div->setAttribute('style', 'page-break-inside:avoid;');
echo $dom->outerHtml;
关于PHP 在字符串中查找带有 id 的元素并添加样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54763101/
相关文章:
html - Bootstrap : 1 col sidebar taking height of the content of the other cols
php - 我们应该在 Amazon MWS PHP SDK 的 APPLICATION_NAME 和 APPLICATION_VERSION 字段中输入什么?
php - 在 SugarCRM 中将国家/地区文本字段更改为下拉列表
javascript - 使用 jquery 禁用 html 表单中的提交按钮的功能,但它仍然可见
twitter-bootstrap - 如何使用 bootstrap 将两个图像 "horizontally"(并排)放在一起,这样它们就不会伸出屏幕?