<body>
<input type="text" name="hello"/>
<br/>
<input type="button" value='复制'/>
</body>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function(){
$("input[type='text']").live('blur',tip);
$("input[type='button']").click(function(){
$("body").prepend($("<input type='text' name='hello'/>"));
});
});
function tip(){
alert('fafafa');
}
</script>结果所有的input[type='text'] 都不能触发blur事件,请问为什么?

解决方案 »

  1.   

    ps:补充一下
    如果把live换成bind,然后添加input 用clone(true)则是能触发blur事件的。
      

  2.   

    ps:jquery是1.5,在jquery1.3之后就开始对blur的live进行支持了
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Jquery Testing</title>
    <script src="jquery-1.5.1.js"></script> </head><body>
    <script type="text/javascript" src="jquery.js"></script>
            <script type="text/javascript">
                $(function(){
                    $("input[type='text']").live('blur',tip);
                    $("input[type='button']").click(function(){
                        $("body").prepend($("<input type='text' name='hello'/>"));
                    });
                });
            function tip(){
                alert('fafafa');
            }
            </script><input type="text" name="hello"/>
        <br/>
    <input type="button" value='复制'/>
    </body>
    </html> 
    经过测试这段代码可以使用,不知道楼主哪里出问题了
      

  4.   

    测试了下,你的代码没问题啊。可能你贴的代码不完整,问题跟你贴出的代码没关系,JS控制台下看看报什么错误。
    http://jsfiddle.net/m6Wx4/
      

  5.   

    我也发现live有问题,前几天在看jquery的api文档,发现有live()这方法,看了介绍感觉不错,写了个例子去测试了一下,发现很好用,于是加到自己的页面里边去,发现就出问题了,我绑定的是click事件,发现没用,改成bind(),有用,click事件里边有7 8十行代码,我也懒得去测试了,功能上已经用另外的方法实现,只是用live()的话,能减少不少代码,以后慢慢研究吧,等把手头上的活干完
      

  6.   

    ps:我是楼主,我的代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>MyXhtml.xhtml</title>
    <meta http-equiv="keywords" content="enter,your,keywords,here" />
    <meta http-equiv="description" content="A short description of this page." />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="jquery.js"></script>
            <script type="text/javascript">
                $(function(){
                    $("input[type='text']").live('blur',tip);

                    $("input[type='button']").click(function(){
                        $("body").prepend($("<input type='text' name='hello'/>"));
                    });
                });
            function tip(){
                alert('fafafa');
            }
            </script>
    </head>
    <body>
    <input type="text" name="hello"/>
            <br/>
            <input type="button" value='复制'/>
    </body>
    </html>
    测试环境:IE8 FF5, 没有错误提示,只是FF的Firebug报:如果 <script> 标签有 "type" 属性,其值应为 "text/javascript" 或者 "application/javascript",但我实在没发现这是哪里错了。
    程序能影响“复制”按钮所触发的click事件,但就是监听不到blur事件
      

  7.   

    ps:我是楼主,我的代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>MyXhtml.xhtml</title>
    <meta http-equiv="keywords" content="enter,your,keywords,here" />
    <meta http-equiv="description" content="A short description of this page." />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="jquery.js"></script>
            <script type="text/javascript">
                $(function(){
                    $("input[type='text']").live('blur',tip);

                    $("input[type='button']").click(function(){
                        $("body").prepend($("<input type='text' name='hello'/>"));
                    });
                });
            function tip(){
                alert('fafafa');
            }
            </script>
    </head>
    <body>
    <input type="text" name="hello"/>
            <br/>
            <input type="button" value='复制'/>
    </body>
    </html>
    测试环境:IE8 FF5, 没有错误提示,只是FF的Firebug报:如果 <script> 标签有 "type" 属性,其值应为 "text/javascript" 或者 "application/javascript",但我实在没发现这是哪里错了。
    程序能影响“复制”按钮所触发的click事件,但就是监听不到blur事件
      

  8.   

    程序能影响“复制”按钮所触发的click事件,但就是监听不到blur事件。
    有错字,“影响”-> 响应还有yibey,你的代码我测试了,和我的一样,没有反应。请大家把自己的代码粘上来,并说明浏览器版本
      

  9.   

    Safari、FF都没问题。测试用的jQuery版本是1.5.2,不知道你用的版本是?
    <script type="text/javascript" src="jquery.js"></script>
    这一行改为1.5.2版本试试:
    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.js" type="text/javascript"></script>
      

  10.   

    呃。首先给大家说声对不起了。
    我把下载的jquery.1....js,改成jquery.js,我一直以为我用的是1.5,结果刚刚我一看源码,原来是1.3.2。
    刚下载1.6.2,试了下,是可以的 
    耽误大家时间了~~~sorry ~~~