通过document.getElementById()或ByName取得的dom元素,在safari下不能得到其自定义属性值
如:
<select id="l" extraInfo="default" onchange="c()">
<option value="1" e="he">hi</option>
<option value="2" e="hee">hii</option>
<option value="3" e="heee">hiii</option>
<option value="4" e="heeee">hiiii</option>
</select>
脚本: function c(){
alert("first select");
if(window.openDatabase){
alert("*****safari*****");
}else{
alert("*****IE*****");
}
alert($("#l").attr("extraInfo"));
alert($("#l option:selected").attr("e"));
var ss=document.getElementById("l").extraInfo;
alert("doc****"+ss);
}
这种情况用JQuery能解决
如:
<select id="l" extraInfo="default" onchange="c()">
<option value="1" e="he">hi</option>
<option value="2" e="hee">hii</option>
<option value="3" e="heee">hiii</option>
<option value="4" e="heeee">hiiii</option>
</select>
脚本: function c(){
alert("first select");
if(window.openDatabase){
alert("*****safari*****");
}else{
alert("*****IE*****");
}
alert($("#l").attr("extraInfo"));
alert($("#l option:selected").attr("e"));
var ss=document.getElementById("l").extraInfo;
alert("doc****"+ss);
}
这种情况用JQuery能解决
本文探讨了在Safari浏览器中使用JavaScript通过document.getElementById()获取DOM元素时,无法正常读取自定义属性的问题,并提供了使用jQuery解决该问题的方法。
1516

被折叠的 条评论
为什么被折叠?



