javascript selectedOptions[0].textContent; 不适用于 IE 或 Firefox
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13753201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
selectedOptions[0].textContent; not working in IE or Firefox
提问by user1868232
function call(op) {
var x = op.selectedOptions[0].textContent;
var n = x.substring(0, 3);
//alert(n);
document.pts.inputbox.value = n;
document.pts.submit();
}
I have a function that grabs the label value from a selected option in a list box, then it disects out the first 3 letters and passes that information on to an input box value.
我有一个函数,它从列表框中的选定选项中获取标签值,然后分解出前 3 个字母并将该信息传递给输入框值。
The issue is with how the js is grabbing the selected options label text content. It seems to work in Chrome just fine, but in firefox17 and IE9 nothing happens. Any suggestions on a better way to get the selected options label value?
问题在于 js 如何抓取选定的选项标签文本内容。它似乎在 Chrome 中工作得很好,但在 firefox17 和 IE9 中没有任何反应。有关获取所选选项标签值的更好方法的任何建议?
EDIT: I can NOT use the options value, that value is reserved for something more specific Everything works fine in JSfiddle.
编辑:我不能使用选项值,该值保留用于更具体的东西在 JSfiddle 中一切正常。
回答by The Alpha
回答by scunliffe
Based on a quick JSFiddle, the selectedOptions
collection isn't widely supported yet.
基于快速JSFiddle,该selectedOptions
集合尚未得到广泛支持。
Fails/Unsupported:
失败/不支持:
- IE10 (Desktop or Metro)
- IE11
- Safari 7
- iOS6 Opera Mini
- Android 4.0.4 Browser
- Android 4.0.4 Firefox Browser
- IE10(桌面或地铁)
- IE11
- 野生动物园 7
- iOS6 Opera Mini
- 安卓 4.0.4 浏览器
- 安卓 4.0.4 火狐浏览器
Works:
作品:
- Chrome 23.0.1271.95
- Opera 12.11
- BlackBerry 10 Browser
- iOS6 Safari
- iOS6 Chrome
- Android 4.0.4 Opera Mobile Browser
- Firefox 53.0
- Edge
- 铬 23.0.1271.95
- 歌剧 12.11
- 黑莓 10 浏览器
- iOS6 Safari
- iOS6 铬
- 安卓 4.0.4 Opera 手机浏览器
- 火狐 53.0
- 边缘