zoukankan      html  css  js  c++  java
  • IE、360浏览器select属性onchange遇到的坑

    在网页头部定义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>
  • 相关阅读:
    纯快排
    Quick Sort(快速排序)
    归并排序 ALDS1_5_B:Merge Sort
    单调栈(POJ2559)
    Sequence
    Codeforces Round #503
    度度熊学队列
    Always Online hdu 6350
    Hills And Valleys
    Problem G. Depth-First Search
  • 原文地址:https://www.cnblogs.com/wqsbk/p/8257578.html
Copyright © 2011-2022 走看看