-1

I want to add the "Select All" option to my drop down list so that i can select all the values in dropdown list by a single click on "Select All" option.

4

2 回答 2

2

In simple words, this is not possible using only HTML. You need JavaScript for this.

于 2013-03-06T06:55:57.070 回答
0

我得到了解决方案。在这里...

<html>
<head>
<style type="text/css"></style>
<script language="javascript">
      function changeSelection(value){

      var length = document.getElementById("ch").options.length;

      if(value == 0){
      for(var i = 1;i<length;i++)
        document.getElementById("ch").options[i].selected = "selected";

      document.getElementById("ch").options[0].selected = "";
      }

  }
</script>
</head>
<body>

<select multiple onchange="changeSelection(this.value)"
     id="ch">
<option value="0">All</option>
<option value="1">C</option>
<option value="2">C++</option>
<option value="3">Java</option>
<option value="4">SQL</option>
<option value="5">HTML</option>
</select>

</body>
</html>
于 2013-03-06T10:18:29.507 回答