日期:2014-05-17  浏览次数:20818 次

html转义字符的比较问题
为什么两次比较都是false, "  "被转成了什么


<SELECT   name= "FILE_SELECT1 ">
    <OPTION   value= "&nbsp; "   selected> blank </OPTION>
</SELECT>

<SCRIPT>
var   sss   =   FILE_SELECT1[0].value;
alert(sss   ==   "&nbsp; ");
alert(sss   ==   "   ");
</SCRIPT>

------解决方案--------------------

<SELECT name= "FILE_SELECT1 ">
<OPTION value= " " selected> blank </OPTION>
</SELECT>

&nbsp;是HTML格式,离开IE解释器就没有任何意义了。

如果 要空 直接按照上面的来写就行了,或者
<SELECT name= "FILE_SELECT1 ">
<OPTION value= " " selected> blank </OPTION>
</SELECT>

------解决方案--------------------
其ASCII码为160,示例如下:

<SELECT name= "FILE_SELECT1 ">
<OPTION value= "&nbsp; " selected> blank </OPTION>
</SELECT>

<SCRIPT>
var sss = FILE_SELECT1[0].value;
alert(sss == " ");
alert(sss.charCodeAt());

var xxx= " ";
alert(xxx== " ");
alert(xxx.charCodeAt());
</SCRIPT>