+ -
当前位置:首页 → 问答吧 → 事件绑定问题

事件绑定问题

时间:2010-03-07

来源:互联网

html代码如:
<input value="添加文件" name="addButton" id="addButton" type="button">

js代码:$('input[name="addButton"]').bind("click",addLine);
function addLine(){
    $('#fileCollection')
}

点击该按钮时,没有按钮提示框弹出。

而当使用 $('#addButton').bind("click",addLine);
绑定时,点击按钮提示框弹出正常。

我使用的浏览器为ie8。
请各位指教。
[ 此帖被fevergreen在2010-03-07 17:56重新编辑 ]

作者: fevergreen   发布时间: 2010-03-07

完全没有问题
复制代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title></title>
  6. <script type="text/javascript" src="jquery-1.3.2.min.js" ></script>
  7. <script type="text/javascript">
  8.     //<![CDATA[
  9.         $(document).ready(function(){
  10.             $('input[name="addButton"]').bind('click',addLine);
  11.         });
  12.         function addLine(){
  13.             alert('jquery is fine');
  14.         }
  15.     //]]>
  16. </script>
  17. </head>
  18. <body>
  19. <input type="button" name="addButton" id="addButton" value="value" />
  20. </body>
  21. </html>

作者: ywqbestever   发布时间: 2010-03-07

谢了,我刚才试错了

作者: fevergreen   发布时间: 2010-03-07