1、$(function(){
$("#a").click(function(){
//adding your code here
});
});
2、$(document).ready(function(){
$("#a").click(function(){
//adding your code here
});
});
3、window.onload = function(){
$("#a").click(function(){
//adding your code here
});
}
html代碼為<input type="button">點(diǎn)擊</input>,且頁(yè)面需要引用jquery的js文件
一般的加載頁(yè)面時(shí)調(diào)用js方法如下:
復(fù)制代碼 代碼如下:
window.onload = function() {
$("table tr:nth-child(even)").addClass("even"); //這個(gè)是jquery代碼
};
但是用jquery的方法:
復(fù)制代碼 代碼如下:
$(document).ready(function() {
// 任何需要執(zhí)行的js特效
$("table tr:nth-child(even)").addClass("even");
});
還有一種簡(jiǎn)寫的方式:
復(fù)制代碼 代碼如下:
$(function() {
// 任何需要執(zhí)行的js特效
$("table tr:nth-child(even)").addClass("even");
});
新聞熱點(diǎn)
疑難解答
圖片精選