为什么我不能在使用js的img title属性中设置ascii引用? [英] why can't I set an ascii reference in an img title attribute using js?
本文介绍了为什么我不能在使用js的img title属性中设置ascii引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在图片标题中使用ascii字符引用(& reg;
)。当你通过html body设置它的时候,它工作的很好,但是当试图通过javascript来做同样的事情时不起作用。
I'm having trouble using an ascii character reference (®
) in an image title. It works fine when you set it via the html body, but when trying to do the same thing via javascript does not work.
检查sscce:
<style type="text/css">body {background-color:black;}</style>
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script>
<p>this image has the correct ascii character title:<br /><img src="http://www.prototypejs.org/images/logo-home.gif" id="img1" title="®" /></p>
<p>but why can't I set the same value via javascript?<br /><img src="http://www.prototypejs.org/images/logo-home.gif" id="img2" /></p>
<script type="text/javascript">
$("img2").title = "®";
</script>
谢谢。
Thanks.
推荐答案
$(\"img2\").title =®should not work,if not use
$("img2").title = "®" should work, if not use
$(img2)。title ='\\ \\ u00AE'。
$("img2").title ='\u00AE'.
不会为纯文本翻译html实体。
The html entities are not translated for pure text.
这篇关于为什么我不能在使用js的img title属性中设置ascii引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文