格式化要由php响应的javascript
我试图呼应出一些JavaScript,但我无法获得正确的格式,我首先将我想要输出的JavaScript放入一个字符串中格式化要由php响应的javascript,php,javascript,Php,Javascript,我试图呼应出一些JavaScript,但我无法获得正确的格式,我首先将我想要输出的JavaScript放入一个字符串中 $javascript = 'onmouseover="this.style.backgroundColor='blue'" onmouseout="this.style.backgroundColor='white'"'; 然后像这样回音 $hint="<span $javascript>".$artistname->item(0)->childN
$javascript = 'onmouseover="this.style.backgroundColor='blue'" onmouseout="this.style.backgroundColor='white'"';
然后像这样回音
$hint="<span $javascript>".$artistname->item(0)->childNodes->item(0)->nodeValue."</span>";
$hint=”“.$artistname->item(0)->childNodes->item(0)->nodeValue。“;
任何帮助都将不胜感激从引用的代码中的颜色可以看出,您需要避开单引号。您最终将得到:
$javascript = 'onmouseover="this.style.backgroundColor=\'blue\'" onmouseout="this.style.backgroundColor=\'white\'"';
从引用的代码中的颜色可以看出,您需要转义单引号。您最终将得到:
$javascript = 'onmouseover="this.style.backgroundColor=\'blue\'" onmouseout="this.style.backgroundColor=\'white\'"';
使用这个词被认为是不好的做法。此外,我不明白为什么必须将属性存储在PHP变量中,而不是直接将它们添加到span标记中。最后但并非最不重要的一点是,当鼠标在跨距上时,为什么不使用更改背景颜色呢?这将是一个干净的方法。使用被认为是不好的做法。此外,我不明白为什么必须将属性存储在PHP变量中,而不是直接将它们添加到span标记中。最后但并非最不重要的一点是,当鼠标在跨距上时,为什么不使用更改背景颜色呢?这将是一个干净的方法。您应该从输出字符串开始。您希望它看起来像这样:
onmouseover="this.style.backgroundColor='blue'"
onmouseout="this.style.backgroundColor='white'"
现在,为了将PHP中的字符串放入变量中,需要用单引号或双引号将其括起来。由于字符串同时包含单引号和双引号,因此需要对其中任何一个进行“转义”
使用单引号:
$javascript = 'onmouseover="this.style.backgroundColor=\'blue\'"
onmouseout="this.style.backgroundColor=\'white\'"';
$javascript = "onmouseover=\"this.style.backgroundColor='blue'\"
onmouseout=\"this.style.backgroundColor='white'\"";
使用双引号:
$javascript = 'onmouseover="this.style.backgroundColor=\'blue\'"
onmouseout="this.style.backgroundColor=\'white\'"';
$javascript = "onmouseover=\"this.style.backgroundColor='blue'\"
onmouseout=\"this.style.backgroundColor='white'\"";
编辑:
最后一点:仔细阅读Gordon发布的内容。您应该从输出字符串开始。您希望它看起来像这样:
onmouseover="this.style.backgroundColor='blue'"
onmouseout="this.style.backgroundColor='white'"
现在,为了将PHP中的字符串放入变量中,需要用单引号或双引号将其括起来。由于字符串同时包含单引号和双引号,因此需要对其中任何一个进行“转义”
使用单引号:
$javascript = 'onmouseover="this.style.backgroundColor=\'blue\'"
onmouseout="this.style.backgroundColor=\'white\'"';
$javascript = "onmouseover=\"this.style.backgroundColor='blue'\"
onmouseout=\"this.style.backgroundColor='white'\"";
使用双引号:
$javascript = 'onmouseover="this.style.backgroundColor=\'blue\'"
onmouseout="this.style.backgroundColor=\'white\'"';
$javascript = "onmouseover=\"this.style.backgroundColor='blue'\"
onmouseout=\"this.style.backgroundColor='white'\"";
编辑:
最后一点:仔细阅读Gordon发布的内容