亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

IE7下js讀取select選取項值的問題

IE7下js讀取select選取項值的問題

LEATH 2018-12-07 03:19:14
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">   <head>     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />     <script type="text/javascript" src="xxx.js"></script>  </head>  <body>     <select id="select">       <option>請選擇項</option>       <option>dasfasdf</option>       <option>123</option>     </select>  </body></html> ? function $(id){   return document.getElementById(id);} window.onload = function(){   $('select').options[0].selected=true;   $('select').onchange=function(){     var objselect=$('select');     var indexselect=objselect.selectedIndex;     var valselect=objselect.options[indexselect].value;     alert(valselect);   } } ? 在IE8、9、10下都能正常運行,chrome下也沒問題,就IE7不行,讀取出來的數據為空,IE6未嘗試,不過估計跟IE7一個樣 麻煩誰幫忙解決下
查看完整描述

1 回答

?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

你的option中并沒有寫value,所以IE7讀取不到,但是其他瀏覽器做過優化,不寫value時默認把text當作value,所以兩種方案:

一、給option加上value屬性

二、用var valselect=objselect.options[indexselect].text;

查看完整回答
反對 回復 2018-12-24
  • 1 回答
  • 0 關注
  • 389 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號