刚才在弄一个ecshop的弹窗
但是firebug报
$(document).ready(.. not a function jquery的路径也检查过了 没错
后来把 $(document).ready 换成
(function(){
...
...
})()
就可以了。
想问一下
(function(){
...
...
})()
这种是什么意思 简写吗
但是firebug报
$(document).ready(.. not a function jquery的路径也检查过了 没错
后来把 $(document).ready 换成
(function(){
...
...
})()
就可以了。
想问一下
(function(){
...
...
})()
这种是什么意思 简写吗
//你的代码
})
这是jquery的用法。
(function(){
...
...
})()这个是你申明了一个匿名函数
然后,立即调用执行它。
常定义的函数:function a(arg0,arg1...){} 它是不会立刻执行的 使用的时候你会这样a(arg0,arg1...);
function(){} 是匿名函数 这种函数你要想让他立刻执行 就需要(function(){})()
(1+1) = 2
(function(){}) = 括号内的函数
(function(){})() 括号内的函数调用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>括号的功效</title>
</head>
<body onload="omload()">
<p>该例中,括号test函数比onload还要早执行
</p>
<script type="text/javascript">
(function test() {
alert("test");
}) () //这个括号不能少 function omload() {alert("omload");}</script>
</body>
</html>
function outer(){
(function(){
///...定义的变量,在outer函数内,匿名函数外无法访问
})()
};楼主还是补补javascript基础吧