function Ctlpurpose() {  
   var obj = document.getElementById("select_1"); //定位id
   var index = obj.selectedIndex; // 选中索引function Ctlpurpose(select_id) {  
   var obj = document.getElementById(select_id); //定位id
   var index = obj.selectedIndex; // 选中索引二种写法都能执行,但带参数的在CHROME中有报错
该如何处理?

解决方案 »

  1.   

    select_id 传的啥啊
      

  2.   

    第二种方式这样调用
    Ctlpurpose("select_1");
      

  3.   

    控件SELECT 的ID
      

  4.   

    你这样写,传的值必须是string类型
      

  5.   


    Uncaught TypeError: Cannot read property 'selectedIndex' of null
      

  6.   

    var index = obj.selectedIndex
    写错了,不能这么用吧
      

  7.   

    alert一下obj.id,看看是不是你需要的对象,如果连id都获取不到,那参数肯定有问题。然后看看浏览器有没有默认选择一个option,如果没有默认选择一个option,肯定获取不到selectedIndex
      

  8.   

    Uncaught TypeError: Cannot read property 'selectedIndex' of null 这句话报错代表你的参数传错了。
      

  9.   


    你这个  onclick=“myclick('myselect')”  不是myselect1
    问题该如何解决,函数写法问题?
      

  10.   

    select 结构代码, 调用  Ctlpurpose(...) 的代码
    报错信息
    先后顺序等信息都一次性贴出来
      

  11.   


    function Ctlpurpose(select_id) {  
           var obj = document.getElementById(select_id); //定位id
           console.log(obj) // 如果打印obj不是一个dom结构,那就是没找到这个id的dom,如果找到就是没有selectedIndex这个属性
           var index = obj.selectedIndex; // 选中索引