Heim  >  Artikel  >  Web-Frontend  >  JavaScript列表框listbox全选和反选的实现方法_javascript技巧

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

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

本文实例讲述了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程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn