最近的文章列表

总结js select option对象 获取option的值

一基础理解:

var e = document.getElementById("selectId");

e. options= new Option("文本","值") ;

//创建一个option对象,即在<select>标签中创建一个或多个<option value="值">文本</option>

//options是个数组,里面可以存放多个<option value="值">文本</option>这样的标签

2014/6/10 Comments:
js获取select标签选中值(option seleced)的两种方式
代码如下:

var obj = document.getElementByIdx_x(”testSelect”);//定位id
var index = obj.selectedIndex;// 选中索引
var text = obj.options[index].text; // 选中文本
var value = obj.options[index].value; // 选中值jQuery中获得选中select值第一种方式
$('#testSelect option:selected').text();//选中的文本
2014/1/16 Comments: