select的option属性value以及text值的获取操作
来源:互联网 发布:sap软件费用 编辑:程序博客网 时间:2024/06/06 23:17
<!DOCTYPE html><html><head><style type="text/CSS"></style></head><body><select id="publish"><option value="1">what is this</option><option value="2">this is select</option><option value="3">oh,thanks</option><option value="4">you are welcome</option></select><div id="testDiv"></div><script type="text/JavaScript" src="publicJQuery/jquery-2.1.4.js"></script><script type="text/JavaScript">function getSelected(){var option=document.getElementById('publish').value;//有value就得到value(1,2,3,4),没有就得到选项值(what is this ...)var obj=document.getElementById('testDiv');obj.innerText=option;}/* 通过option直接取得值*/function getSelectedTwo(){var options=document.getElementsByTagName('option');var obj=document.getElementById('testDiv');for(var i=0; i<options.length; i++){if(options[i].selected==true){obj.innerText="value值为:"+options[i].value+"。text值为:"+options[i].text;//options[i].innerText也可以}}}/* 通过索引值selectedIndex来取得值*/function getSelectedThree(){var select=document.getElementById('publish');var selectedIndex=select.selectedIndex;//alert(selectedIndex);//索引为0123var obj=document.getElementById('testDiv');obj.innerText="value值为:"+select.options[selectedIndex].value+"。text值为:"+select.options[selectedIndex].text;}/* jQuery用法,为什么用的是val()跟text(),因为jQuery是js库,所以这里的val()跟text()是调用的方法,上面的原生的js的value跟text是原生js的属性。*/function getSelectedFour(){var selected=$("#publish option:selected");var value=selected.val();var text=selected.text();var obj=document.getElementById('testDiv');obj.innerText="value值为:"+value+"。text值为:"+text;}document.getElementById('publish').onclick=getSelectedFour;</script></body></html>
0 0
- select的option属性value以及text值的获取操作
- jquery select option 根据value值获取text文本,option中间的文本
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和 Value(转)
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和 Value(转)
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- jquery 获取Select option 选择的Text和Value
- 【转载】jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- 获取select中option的value值
- 如何获得select被选中option的value和text和其他属性值
- JavaScript获取Select下拉框Option的Value和Text值的方法
- js实例,获取选中select标签的value和option text值
- ExamDao
- Java集合类操作优化总结
- 日期转化
- Sql Server 日期函数
- POJ 3080 Blue Jeans(字符串处理)
- select的option属性value以及text值的获取操作
- [Android]attrs.xml的自定义VIEw
- Android像素与dip的关系
- 项目管理经验总结
- GDB使用小结
- 飞秋实现的原理
- DFA与NFA
- hdu 2037 今年暑假不AC
- SSH加密原理、RSA非对称加密算法学习与理解