1
我有一个简单的脚本,当标题匹配时,它正在寻找一个标题来执行一个函数。我遇到了版权和注册商标等特殊字符的问题。引发问题的jQuery特殊字符
var isDisclosure = $('.disclosure-container h3').html();
if (isDisclosure == "Awesome Product<sup>®</sup> Disclosures") {
alert('zomg');
}
的HTML看起来像这样的萤火:
<h3 class="inline">
Awesome Product
<sup>®</sup>
Disclosures
</h3>
在查看HTML看起来像这样的源...
<h3 class="inline">Awesome Product<sup>®</sup> Disclosures</h3>
所以,当我是HTML添加到,如果声明,我得到一个额外的字符,它不工作...像这样...
if (isDisclosure == "Awesome Product<sup>©</sup> Disclosures")
我很开放,只是用通配符或最后的东西搜索“Awesome Product”。
那么,在这种情况下,你可以做'如果(isDisclosure.indexOf( “真棒产品”)=== 0){...':) – techfoobar
您是否尝试过使用它转换HTML实体的功能等一个[这里](http://stackoverflow.com/questions/1912501/unescape-html-entities-in-javascript)并用它来填充你的字符串。换句话说'if(isDisclosure ==“Awesome Product ”+ htmlDecode(“&#174”)+“ Disclosures”)' – Jnatalzia