show/hide drop down

后端 未结 4 1033
野的像风
野的像风 2021-01-26 07:28

here is my code:




 New Document 


        
4条回答
  •  深忆病人
    2021-01-26 08:27

    as a side issue you dont need the style.visibility... line

    one more thing:

    Typically, its better to add event listeners using the attachEvent or addEventListener methods (allows more control, and multiple listeners for one action) like this:

    function addEvent(el, eType, fn, uC) {
      if (el.addEventListener) {
        el.addEventListener(eType, fn, uC);
        return true;
      } 
      else if (el.attachEvent) {
        return el.attachEvent('on' + eType, fn);
      }
      else {
        el['on' + eType] = fn;
      }
    }
    

    and then just use

    addEvent(
        document.getElementById("radio1"),
        "change",
        function(){
          if(this.checked == true){
                document.getElementById("list1").style.display = "none";
          }
        },
        false);
    

    This is both cross-browser and better practice

提交回复
热议问题