<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事件,请问为什么?
如果把live换成bind,然后添加input 用clone(true)则是能触发blur事件的。
<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>
经过测试这段代码可以使用,不知道楼主哪里出问题了
http://jsfiddle.net/m6Wx4/
<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事件
<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事件
有错字,“影响”-> 响应还有yibey,你的代码我测试了,和我的一样,没有反应。请大家把自己的代码粘上来,并说明浏览器版本
<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>
我把下载的jquery.1....js,改成jquery.js,我一直以为我用的是1.5,结果刚刚我一看源码,原来是1.3.2。
刚下载1.6.2,试了下,是可以的
耽误大家时间了~~~sorry ~~~