Calling javascript functions from drop down

前端 未结 2 1369
甜味超标
甜味超标 2021-01-06 15:59

I have this HTML code at the moment:

Theme
  • Choose theme
相关标签:
2条回答
  • 2021-01-06 16:10

    Demo: http://jsfiddle.net/zYMFa/

    Use values for options and handle change event for select. The value property of select gets value of the selected option, so you can use this.value in change function.

    <form>
    <select id="myList" >
      <option value="default">Default</option>
      <option value="theme1">Theme 1</option>
      <option value="theme2">Theme 2</option>  
      <option value="theme3">Theme 3</option>
    </select>
    <form>
    
    document.getElementById("myList").onchange = function() {
       setActiveStyleSheet(this.value);
       return false
    };
    
    0 讨论(0)
  • 2021-01-06 16:25
    <select id="myList" >
      <option id="stylesheet1" value="default">Default</option>
      <option id="stylesheet2" value="one">Theme 1</option>
      <option id="stylesheet3" value="two">Theme 2</option>  
      <option id="stylesheet4" value="three">Theme 3</option>
    </select>
    
    document.getElementById("myList").onchange = function() {
       var sheet=document.getElementById("myList").value;
    
       if(sheet=="one"){
       setActiveStyleSheet("theme1");
       }
       else if(sheet=="two"){
       setActiveStyleSheet("theme2");
       }
       else if(sheet=="three"){
       setActiveStyleSheet("theme3");
       }
       else{
       setActiveStyleSheet("default");
       }
       return false
    };
    
    0 讨论(0)
提交回复
热议问题