在一个页面中,先执行document.getElementById("thisdiv").innerHTML="<select id='ss'><option value='ff'>aa</option>........</select>";
就是添加了一个SELECT,但是这个SELECT的OPTION很多,有二百个,然后成功看到期望的SELECT出现在页面上。
然后对这个select随便选一个值,执行下面句子
var thisss=document.getElementById(‘ss');
alert("selected index"+ss.selectedIndex);但是很郁闷的是,不管选第几个值,这个alert总是报告"selected index0"。为什么老是0,明明不是0啊,我很崩溃,各位有遇见这种情况吗?可能是哪儿出了问题,请教了!
谢谢。

解决方案 »

  1.   

    var thisss=document.getElementById(‘ss');
    alert("selected index"+ss.selectedIndex);
    应该为alert("selected index"+thisss.selectedIndex);
      

  2.   

    alert("selected index"+thisss.value);
      

  3.   

    抱歉是我贴代码贴错了,就是thisss,
    var thisss=document.getElementById(‘ss');
    alert("selected index"+thisss.selectedIndex);
    问题还是上面的,仍然等待回答!!!
      

  4.   

    <script language=javascript>
    var str='<select onchange="alert(this.selectedIndex)" size="1" name="D1" id="s1"><option value="a">a</option><option value="b">b</option></select>'
    document.body.innerHTML=str;
    </script>
      

  5.   

    lz看看你每个option 的value是否是一样的?
      

  6.   

    这个是我贴错了,程序中是thisss来着,你想啊,如果是我变量写错了,它肯定要说null没有selectedIndex属性了,而不是给我个0。
      

  7.   

      <script language="javascript">
      document.getElementById("xx").onchange=function(){
      
      alert("selected index"+document.getElementById("xx").selectedIndex);
      }
      </script>
      

  8.   

    不一样,生成如下:
    <select id='mygeness'><option value='3'>3</option><option value='6'>6</option><option value='9'>9</option><option value='12'>12</option><option value='15'>15</option><option value='18'>18</option><option value='21'>21</option><option value='24'>24</option><option value='27'>27</option><option value='30'>30</option><option value='33'>33</option></select><input type='button' onclick='searchpage(1,-1)' value='去到这一页'></button>
      

  9.   

    selectedIndex没错的
    是不是你的页面代码头部上加上了w3c之类的html代码,把那些去掉试试
      

  10.   

    多谢各位,问题解决了,我是这样做的,定义一个全局变量,那个select一变我就把它的selectedindex赋给那个全局变量,再提交时读这个全局变量,就OK了。