当前位置:编程学习 > JS >>

js动态创建控件不支持事件

var div = document.createElement("div");
      var f = document.createElement("input");
      f.setAttribute("type", "text")
      f.setAttribute("name", "text"+thumbs)
   f.setAttribute("class","b")
      f.setAttribute("size", "40")
      div.appendChild(f)
   var w=document.createElement("input");
   w.setAttribute("type", "button")
   w.setAttribute("name", "button1")
   w.setAttribute("class","input2")
   w.setAttribute("value", "上传图片")
      w.setAttribute("onclick", "javascript:window.open('/fd_upload/upload.asp?formname=add_pro&typ=smail&editname=text"+thumbs+"&imagename=image1&uppath=/fd_upimg/product/small','','status=no,scrollbars=no,top=310,left=380,width=420,height=165')")
      div.appendChild(w)
      document.getElementById("_container").appendChild(div);
    }

创建这样一个按钮点击时,里面的onclick事件没反应,,在IE8可以。

答案:
 $("#dhang").append("div>地址:<input type='text' onclick="test();"  class='textbox' name='ttturl'  id='turlid' /></div>");

上一个:JS调用iframe问题
下一个:请教zend framework 加载js - 技术问答

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,