2012-12-06 23 views
16
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(); 
} 

不工作我有抓住從列表框中選擇的選項的標籤值的函數,那麼它disects出前3個字母並傳遞到輸入框值的信息。selectedOptions [0] .textContent;在IE或Firefox

問題在於js如何抓取選定的選項標籤文本內容。它似乎在Chrome中工作得很好,但在firefox17和IE9中沒有任何反應。任何建議更好的方式來獲得選定的選項標籤值?

編輯: 我不能使用選項值,該值是爲更具體的東西保留 一切工作正常JSfiddle。

+0

您是否考慮過在'

+0

您可以嘗試將您的代碼放在http://jsfiddle.net網站上,以便我們可以輕鬆進行調查嗎? –

+0

是的,我不能使用選項值,該數字是爲了別的。 – user1868232

回答

20

試試這個

function call(op) { 
    var x = op.options[op.selectedIndex].text; 
    var n = x.substring(0, 3); 
    alert('Index : '+op.selectedIndex+' and first 3 lettrs are : '+n); 
} 

DEMO

11

基於快速JSFiddleselectedOptions集合尚未得到廣泛支持。

失敗/不支持:

  • IE10(桌面或地鐵)
  • IE11
  • Safari瀏覽器7
  • iOS6的Opera Mini的
  • 的Android 4.0.4瀏覽器
  • 的Android 4.0 .4 Firefox瀏覽器

作品:

  • 的Chrome 23.0.1271.95
  • 歌劇12.11
  • 黑莓10瀏覽器
  • iOS6的Safari瀏覽器
  • iOS6的鍍鉻
  • 的Android 4.0.4的Opera Mobile瀏覽器
  • Firefox 53.0
  • 邊緣
+0

相關文章[這裏](https://stackoverflow.com/q/10711767/465053)。 – RBT

相關問題