簡體   English   中英

jQuery模糊事件不起作用

[英]jQuery blur event not working

為什么下面的代碼中的模糊事件不起作用,並且在文檔准備好后立即彈出警報框,而不等待模糊事件。 給我建議修復它...謝謝...

 <!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作為參數。 在您的代碼中,您會得到cc函數執行的結果。

您應該使用匿名函數:

$(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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM