.ready()内部函数作用域问题
使用jQuery的.ready()方法后,内部函数可能出现无法被外部调用的问题,如下
$(document).ready(function() { function Alert() { alert("hello"); }; });
此时Alert()将无法被button调用;而另一种情况如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script> </head> <button id="btn" onclick="Alert()">弹出</button> </body> </html>
$(document).ready(function() { var Alert=function() { alert("hello"); }; });
这个时候Alert()就可以被外部调用了;