1. $(".tab").click(function () { })
2. $(".tab").on("click",function () { })
3. $(document).on("click", ".tab",function () { })
4. 使用
function load(){
//下面两种方法效果是一样的
document.getElementById("target").onclick();
document.getElementById("target").click();
}
$(function(){
// test 的点击事件
$("#test").click(function(){
alert("点击了");
});
// 调用 test 的点击事件的两种方法
$("#test").trigger("click");
$("#test").click()
})
JQuery绑定click事件的3种写法:
$(document).ready(function(){
$("#text").bind("click",function(){
alert("我的id为text,你点击时触发");
});
$("#text1").on("click",function(){
alert("hellworl");
});
$("#text2").click(function(){
alert($("#text2").val());
});
});