$(document).ready(function(){
//this is your code...
});
$().ready(function(){
//this is your code...
})
$(function(){
//this is your code...
})
以上三种写法等价~~~
.bind('click',function(){
//this is your code....
})
.click(function(){
//this is your code...
})
以上两种等价,皆是单击事件~~~
.bind()是绑定事件时所用
.unbind()是移除停用的事件处理程序,写法和.bind()类似。
-------------------------------------------------------------------------------------------------------------------------------------------------------------
$(selector).toggle(function1(),function2(),functionN(),...)
参数 | 描述 |
---|---|
function1() | 必需。规定当元素在每偶数次被点击时要运行的函数。 |
function2() | 必需。规定当元素在每奇数次被点击时要运行的函数。 |
functionN(),... | 可选。规定需要切换的其他函数。 |
切换 Hide() 和 Show()
$(selector).toggle(speed,callback)
参数 | 描述 |
---|---|
speed | 可选。规定 hide/show 效果的速度。默认是 "0"。 可能的值:
|
callback | 可选。当 toggle() 方法完成时执行的函数。 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
.hover() 突出显示位于鼠标指针下方的页面元素。
$(selector).hover(function1(),function2(),functionN(),...)
参数 | 描述 |
---|---|
function1() | 必需。鼠标下方的页面元素的执行事件。 |
function2() | 必需。离开鼠标下方的页面元素的执行事件。 |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
.stopPropagation() 完全阻止事件冒泡。
.preventDefault() 在触发默认操作之前终止事件。
同样的,如若想要同时停止事件传播和默认操作,可以在事件处理程序中返回false,这是以上2种方式的简写。
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
.trigger()引发执行绑定的事件处理程序。
$(selector).trigger('click');
以上2种写法等价,意思是先执行click事件$(selector).click();