$("#btn").click(function(){ });只有在页面加载的时候才会有效触发
例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/jquery-2.0.0.js"></script> <script> var j = ""; $(function(){ j = 1; $("#btn").click(function(){ //函数在$(function(){})内 alert(j); }); }); </script> </head> <body> <input type="button" value="按钮" id="btn" /> </body> </html>