A-A+
jquery和javascript中select的用法介绍
javascript用法,代码如下:
- var obj=document.getElementById(selectid);
- obj.options.length = 0; //清除所有内容
- obj.options[index] = new Option("three",3); //更改对应的值
- obj.options[index].selected = true; //保持选中状态
- obj.add(new Option("4","4")); ”文本",”值"
- var index = obj.selectedIndex;obj.options.remove(index);//删除选中项
其它,getElementsByTagName的用法,例子,代码如下:
- var temp=document.getElementsByTagName("input");
- for (i = 0; i < temp.length; i++) {
- if (temp[i].id != "" && temp[i].id!=null) {
- document.getElementById(temp[i].id).value = "";
- }
- }
jquery,代码如下:
- $("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项)
- $("#select_id").").find('option:selected').text(); 获取select选中的text
- $("#select_id").val(); 获取select选中的value
- $("#select_id option[index='0']").remove();//删除索引值为0的Option
- $("#select_id option[value='3']").remove(); //删除值为3的Option
- $("#select_id option").remove(); //删除TEXT值为4的Option
- $("#mselect_id").change(function(){ //添加所需要执行的操作代码})