首页 > 其他 > 详细

IE浏览器select属性onchange遇到的坑

时间:2018-01-10 13:30:34      阅读:254      评论:0      收藏:0      [点我收藏+]

在网页头部定义js代码


<script type="text/javascript"> function gradeChange(e){ var selectId = document.getElementById("selectId"); var index = selectId.selectedIndex; var value = selectId.options[index].value; var id = selectId.options[index].id; document.getElementById(id).setAttribute(disabled,disabled); var ul = document.getElementById("ul"); var li = document.createElement("li"); li.setAttribute(id,li_+id); li.setAttribute(onclick,del(+id+)); var span = document.createElement("span"); span.innerHTML =value+×; li.appendChild(span); ul.appendChild(li); selectId[0].selected = true; var hide = document.getElementById("hotTagName"); if(hide.value==‘‘ || hide.value=="null"){ hide.setAttribute(value,value); }else{ hide.setAttribute(value,hide.value+,+value); } } </script>
<body> 
<select style="float:left;" id="selectId" onchange="javascript:gradeChange(this);"> <option value="">--热点标签--</option> <logic:notEmpty name="tagList"> <logic:iterate id="tag" name="tagList" indexId="i"> <option id="id_${i}" value ="${tag.name}">${tag.name}</option> </logic:iterate> </logic:notEmpty> </select>
<body>

 

IE、360报错gradeChange方法未定义,不兼容问题谷歌、火狐正常。

经过考虑之后把代码定义在 <BODY>里,打开页面默认加载js方法

全部兼容了

<body>
<select style="float:left;" id="selectId" onchange="javascript:gradeChange(this);"> <option value="">--热点标签--</option> <logic:notEmpty name="tagList"> <logic:iterate id="tag" name="tagList" indexId="i"> <option id="id_${i}" value ="${tag.name}">${tag.name}</option> </logic:iterate> </logic:notEmpty> </select>
<script> function gradeChange(e){ var selectId = document.getElementById("selectId"); var index = selectId.selectedIndex; var value = selectId.options[index].value; var id = selectId.options[index].id; document.getElementById(id).setAttribute(disabled,disabled); var ul = document.getElementById("ul"); var li = document.createElement("li"); li.setAttribute(id,li_+id); li.setAttribute(onclick,del(+id+)); var span = document.createElement("span"); span.innerHTML =value+×; li.appendChild(span); ul.appendChild(li); selectId[0].selected = true; var hide = document.getElementById("hotTagName"); if(hide.value==‘‘ || hide.value=="null"){ hide.setAttribute(value,","+value); }else{ hide.setAttribute(value,hide.value+,+value); } } </script>
</body>

 

IE浏览器select属性onchange遇到的坑

原文:https://www.cnblogs.com/wqsbk/p/8257578.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!