我尝试将type输入字段的属性更改为number(hidden默认情况下它们具有类型)并添加readonly="readonly",但它对输出 HTML 没有影响。属性和以前一样。
函数触发正常,因为在我添加编码之前,它在页面上显示了错误的字符。我有合适的 CSS 来格式化只读输入,所以视觉效果不是问题,我还将使用更多条件来仅查找特定的输入标签,但现在我想让这段代码正常工作:
add_filter('the_content', 'acau_lock_input');
function acau_lock_input($content) {
$dom = new DOMDocument();
@$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
foreach ($dom->getElementsByTagName('input') as $node) {
$node->setAttribute('type', 'number');
$node->setAttribute('readonly', 'readonly');
}
$newHtml = $dom->saveHtml();
return $newHtml;
}
呼啦一阵风