js操作select option
来源:互联网 发布:c语言求平方根的算法 编辑:程序博客网 时间:2024/05/16 11:41
1、获取选中select的value和text,html代码如下:
<select id="mySelect">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
则可通过以下script代码s来获取选中的value和text
$("#mySelect").val(); //获取选中记录的value值
$("#mySelect option:selected").text(); //获取选中记录的text值
2、运用new Option("文本","值")方法添加选项option
var obj = document.getElementById("mySelect");
obj.add(new Option("4","4"));
3、删除所有选项option
var obj = document.getElementById("mySelect");
obj.options.length = 0;
4、删除选中选项option
var obj = document.getElementById("mySelect");
var index = obj.selectedIndex;
obj.options.remove(index);
5、修改选中选项option
var obj = document.getElementById("mySelect");
var index = obj.selectedIndex;
obj.options[index] = new Option("three",3); //更改对应的值
obj.options[index].selected = true; //保持选中状态
var obj = document.getElementById("mySelect");
obj.parentNode.removeChild(obj); //移除当前对象
7、select选择的响应事件
$("#mySelect").change(function(){
//添加所需要执行的操作代码
})
0 0
- js 操作select option
- js操作select option
- js操作select option
- js 操作select option
- js操作select option
- js操作select option
- js操作select option
- js 操作select和option
- js 操作select和option
- js 操作select和option
- js 操作select和option
- js 操作select和option
- js 操作select和option
- js 操作select和option(转载)
- js select的option的操作
- JS操作select控件的option
- 05-js 操作select和option
- JS动态创建select 操作select和option
- android笔记3——项目文件结构说明
- 失败未必不英雄
- web状态代码详解
- 关闭 C4996 警告
- 无法解析的外部符号 "public: virtual struct CRuntimeClass
- js操作select option
- CCDirector类的成员数据
- 路由器常用配置命令
- 在Service中新开线程和直接新开线程的区别与意义
- MyISAM和Innodb比较
- IOS md5
- 便携式医疗电子将科幻场景搬进生活
- 使用sqlmap进行sql注入
- 横屏小游戏--萝莉快跑源码分析二