<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="Chrom下Javascript工作不正常注意检查ID属性" id="card1">
<p> 游客</p><p>
标题:Chrom下Javascript工作不正常注意检查ID属性<br/>
正文:<br/>
 调试一个包括Javascript的网页，其中涉及货币格式的显示，怎么弄都是在chrome下显示不正常，在IE下正常。更换js库文件也不行。然后通过chrome逐行调试，发现问题没有出现在格式转换上，而是出现在页面元素的命名上面，非IE浏览器许多只支持元素的id属性，通过id属性来命名元素，而不是name属性，如果你的元素只有name属性，在IE下工作正常，但是在非ie浏览器下，如chrome，fireforx，360，淘宝等浏览器下就无法正常工作。所以，必须为页面上的每个元素，要用到的每个元素定义id属性。 Quick Cross Browser JS question, when setting the value of a textbox: document.getElementById(&amp;quot;balanceText&amp;quot;).innerText = &amp;quot;111&amp;quot;;and document.getElementById(&amp;quot;balanceText&amp;quot;).value = &amp;quot;111&amp;quot;;Both Work grand in IE, But they will not work in Chrome, FF, Opera or Safari. Is there an alternate method that will work in these browsers ? 在http://stackoverflow.com/questions/7714162/document-getelementbyid-innertext-in-chrome找到的答案：All else being equal document.getElementById(&amp;quot;balanceText&amp;quot;).value = &amp;quot;111&amp;quot;; works fine in every significant* browser that supports JS. Make sure that you have one, and only one, element with id=&amp;quot;balanceText&amp;quot; and th<br/><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=711&amp;Page=1">[&lt;&lt;]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=711&amp;Page=1">[[1]]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=711&amp;Page=2">[2]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=711&amp;Page=2">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=711">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=711">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://www.zhongguosou.com/blog/wap.asp">首页</a>
</p>
</card>
</wml>