[英]jQuery blur event not working
why blur event in the below code is not working and the alert box pop-ups as soon as the document is ready and not wait for blur event. 为什么下面的代码中的模糊事件不起作用,并且在文档准备好后立即弹出警报框,而不等待模糊事件。 give me suggestion to fix it... Thanks...
给我建议修复它...谢谢...
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ $("[type=text]").blur(cc("[type=text]")); $("[type=email]").blur(cc("[type=email]")); function cc(s){ alert("Value: " + $(s).val()); } }); </script> </head> <body> <input type="text" id="test" value="rev"><br> <input type="email" id="test" value="mail@example.org"> </body> </html>
blur()
function take function as a parameter. blur()
函数将function作为参数。 In your code you pas result of cc
function execution. 在您的代码中,您会得到
cc
函数执行的结果。
You should use anonymous functions: 您应该使用匿名函数:
$(document).ready(function(){
$("[type=text]").blur(function() { cc("[type=text]"); });
$("[type=email]").blur(function() { cc("[type=email]"); });
function cc(s){
alert("Value: " + $(s).val());
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.