日期:2014-05-16 浏览次数:20433 次
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
alert($("#test").html());
</script>
</head>
<body>
<div id="test">1111</div>
</body>
</html>
------解决方案--------------------
楼主已经做过测试了,得到的结论是:省了好像也没啥区别
你们为什么不能正面回答呢?
如果你知道“类”的话,这个匿名函数就等价于类的构造函数
如果你不打算让他做什么,那当然可以省略
如果其中有代码,那么一定在实例化时第一时间执行
------解决方案--------------------
不可以省略,如果是给一个按钮添加一个onclick事件就发生问题了,如下代码
jQuery(".button").click(function() {
alert("button是一个按钮的class属性!");
}