<body>
<div id="div_sel"></div></body>
</html>
<script type="text/javascript" >
var kk="hellozhanghua";
var cs="<select id='select1' size='40'  ><option value='1'  onclick='cs()'>标准标准标准</option></select>";
document.getElementById("div_sel").innerHTML=cs;
function cs(){
alert("hello");
}
</script>一段很简单的代码,我这里onclick事件不能被执行,为什么哦?

解决方案 »

  1.   


    var kk="hellozhanghua";
    var cs=" <select id='select1' size='40' onchange='cs()' > <option value='1''>标准标准标准 </option>
      

  2.   

    option 没有onclick
    onclick可以应用在select上
    你这种情况要用onchange,然后判断是不是选择的那一项
      

  3.   

    4楼正解!去看看W3C标准,option是没有onclick事件的
      

  4.   

    可以在select标签里面写onchange事件嘛
      

  5.   

    我感觉改成 onchange 也不行吧,楼主你的 这个脚本能执行通过吗?你的innerHTML里面的引号不用转译就可以执行吗?感觉很怪,你的这个脚本应该都没替换成功,还  onclick 个什么啊 !
      

  6.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <div id="divsel"></div></body>
    </html>
    <script type="text/javascript" >var cs="<select id='select1' size='40'   ><option value='1'  onclick='cs1()'>标准标准标准</option><option value='2'  onclick='cs1()'>标准标准标准</option></select>";
    document.getElementById("divsel").innerHTML=cs;
    function cs1(){
    alert("hello");
    }</script>
    不知道各位有没有测试哦,我在火狐上是可以触发onclick事件的呀
      

  7.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档 </title>
    </head><body>
    <div id="divsel"> </div></body>
    </html>
    <script type="text/javascript" >var cs=" <select id='select1' size='40' onclick='csIE()' > <option value='1'  onclick='cs1()'>标准标准标准 </option> <option value='2'  onclick='cs1()'>标准标准标准 </option> </select>";
    document.getElementById("divsel").innerHTML=cs;
    function csIE(){
    var oList=document.getElementById('select1');
    alert(oList.options[oList.selectedIndex].firstChild.nodeValue);
    }function cs1(){
    alert("hello");
    }
    </script> 
    ie不支持option上的onclick,但是ff支持。ie支持select上的onclick