JavaScript控制listbox列表框的项目上下移动的方法

前端之家收集整理的这篇文章主要介绍了JavaScript控制listbox列表框的项目上下移动的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了JavaScript控制list@R_301_460@列表框的项目上下移动的方法分享给大家供大家参考。具体分析如下:

这段JS代码可以控制list@R_301_460@内的元素向上或者向下移动,这个功能非常有用。下面是详细的代码

代码如下:
301_460@_move(listID,direction) { var list@R_301_460@ = document.getElementById(listID); var selIndex = list@R_301_460@.selectedIndex; if(-1 == selIndex) { alert("Please select an option to move."); return; } var increment = -1; if(direction == 'up') increment = -1; else increment = 1; if((selIndex + increment) < 0 || (selIndex + increment) > (list@R_301_460@.options.length-1)) { return; } var selValue = list@R_301_460@.options[selIndex].value; var selText = list@R_301_460@.options[selIndex].text; list@R_301_460@.options[selIndex].value = list@R_301_460@.options[selIndex + increment].value list@R_301_460@.options[selIndex].text = list@R_301_460@.options[selIndex + increment].text list@R_301_460@.options[selIndex + increment].value = selValue; list@R_301_460@.options[selIndex + increment].text = selText; list@R_301_460@.selectedIndex = selIndex + increment; } //.. //.. list@R_301_460@_move('countryList','up'); //move up the selected option list@R_301_460@_move('countryList','down'); //move down the selected option
下面是详细的演示代码,可以在浏览器内使用
代码如下:
301_460@.

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

猜你在找的JavaScript相关文章