Home  >  Article  >  Web Front-end  >  JavaScript列表框listbox全选和反选的实现方法_javascript技巧

JavaScript列表框listbox全选和反选的实现方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 16:08:511859browse

本文实例讲述了JavaScript列表框listbox全选和反选的实现方法。分享给大家供大家参考。具体分析如下:

通过JS代码对列表框进行全选和反选是经常要操作的,非常具有实用价值。

function listboxSelectDeselect(listID, isSelect) {
  var listbox = document.getElementById(listID);
  for(var count=0; count < listbox.options.length; count++) {
      listbox.options[count].selected = isSelect;
  }
}

下面是一个详细使用范例

Click below buttons to select or deselect all options from select box


<script> function listboxSelectDeselect(listID, isSelect) { var listbox = document.getElementById(listID); for(var count=0; count &lt; listbox.options.length; count++) { listbox.options[count].selected = isSelect; } } </script>

希望本文所述对大家的javascript程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn