- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 PHP DOMDocument 库来创建一个带有 javascript 值的“脚本”标记元素并将其插入 DOM。
这是我的做法:
$scriptElement = $doc->createElement('script',$scriptTagVal);
echo $scriptElement->nodeValue;
$someNode->parentNode->insertBefore($scriptElement,$postRttScriptNode);
这符合我的预期,它在“someNode”之前插入了一个元素。但是,它做了一些奇怪的事情,它混淆了符号 (&)。单符号 (&) 不存在,双符号 (&&) 被购买为单符号。
疯了吗?好吧,我试过这样做:
$scriptElement = $doc->createElement('script','return "undefined" !== typeof b **&&** null !== b ? b.getAttribute("content") : 0');
如果我回显 $scriptElement->nodeValue,
我明白了
return "undefined" !== typeof b **&** null !== b ? b.getAttribute("content") : 0'
我假设这几乎是闻所未闻的,但我尝试创建不同的元素,其值包含双符号。像这样的东西:
$scriptElement = $doc->createElement('p','Why does DOMDocument obfuscate double
ampersands(&&)');
输出到我的浏览器的结果是一个
标签,其值为:
为什么 DOMDocument 会混淆 double 符号(
也许是特殊字符?无论如何我可以解决这个问题吗?我的意思是,肯定有一种方法可以使用 DOMDocument 在 HTML 中插入 javascript,对吧?
最佳答案
如 http://www.php.net/manual/en/domdocument.createelement.php 中所述
The value will not be escaped. Use DOMDocument::createTextNode() to create a text node with escaping support
有了它你可以试试:
$doc = new DomDocument();
$scriptContent = 'return "undefined" !== typeof b **&&** null !== b ? b.getAttribute("content") : 0';
$scriptElement = $doc->createElement('script');
$scriptElement->appendChild($doc->createTextNode($scriptContent));
$doc->appendChild($scriptElement);
echo $doc->saveXML();
在构建文本节点时,您可能需要使用 $doc->ownerDocument->createTextNode()
,这是未经测试的,因为我没有可运行的代码片段。
关于PHP DOMDocument createElement 混淆符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24376808/
我覆盖了React.createElement,但是jsx的按钮好像没有调用React.createElement。 React.createElement 没有获取到 jsx 的值作为按钮。 最佳答
我支持一些旧版 JavaScript。 在 IE8 中这有效: var hi = forms[i].document.createElement('INPUT'); 在 IE 11 中,该代码会引发异
我需要在 html 代码中查找并替换一些 html 元素(我遵循了这个答案:Getting an element from PHP DOM and changing its value),为此我检索了
我是 JavaScript 中 createElement 属性的新手。我需要从 MySQL 查询创建一个下拉菜单。我从 MySQL 查询创建了一个 PHP 数组,如下所示: 然后我写了JavaSc
function ytplayer_render_playlist(){ for(var i=0;i', { src: "http://img.youtube.com/vi/" + y
我有一些代码在 main.js 文件中复制 Javascript 重复示例: Example 1 for (i = userVote; i function createElement(elemen
.dot{ width: 8px; height: 8px; border-radius: 4px;
这个问题在这里已经有了答案: jQuery DOM changes not appearing in view source (5 个答案) 关闭 8 年前。 我编写此脚本是为了了解如何使用 cre
函数 A() { this.myProp = document.createElement("div"); function B(id) { this.myProp.id = id;
我有以下代码: function JS_Utils_BuildModal () { var objModal = document.createElement(
我的 React 应用程序出现了一些问题。我正在实现功能 authUser,现在我收到如下错误: TypeError: Cannot read property 'createElement' of
为什么会 console.log(document.createElement("p").appendChild(document.createTextNode("some text"))); 返回
我正在尝试创建一个元素并向其附加一个子节点,但我的返回只是一个没有该元素的字符串。 我首先创建元素 const li = document.createElement('li'); 其次,我使用以下命
为什么这段代码不起作用?当我使用注释部分而不是表格时,它起作用了......使用table为什么不能工作? function addLine() {
是否有任何解决方案可以在纯 JavaScript 中构建使用 in div 的多个 div? jQuery 版本 for (var i = 1; i new divs') } http://jsf
CSS div.online:last-child { color:green; } div.offline:last-child { color:green; } JavaScipt
我为我的网站下载了一个 livesearch JavaScript 插件,它可以工作,但我需要帮助来稍微修改它。 代码如下: $.ajax({url: $('base').attr('href
这是我要创建的 HTML: Tiana is ... keen to go to the ... market. 如您所见,有一个 包含散文句子的元素,中间带有选择框。 使用 $('#id').h
我正在尝试使用 document.createElement('circle') 来处理 svgs 但 Chrome 会创建一个结束标记来圈出 错误的结果。如何创建没有结尾的元素? 最佳答案 你可能
我正在尝试用 javascript 创建这个 html block : name }}" type="checkbox" class="minimal"> text 我有: var che
我是一名优秀的程序员,十分优秀!