jq父级绑定事件的意义_jq——事件
$(document),$(body)
加載事件:
$(document).ready(fn)
$(document).ready(function(){ alert("這是加載事件"); });
簡寫:$(function(){});工作中簡寫比較多
js:window.οnlοad=fn? ?把頁面上的DOM和資源加載完成之后執行
jq:$(document).ready(fn)? 把頁面的DOM加載完成之后就會執行
jq來源于js,超越js
事件切換
hover(hover,out);
事件:
1 $(selector).click(fn):selector的點擊事件會觸發fn
2 $(selector).dblclick(fn):selector的雙擊事件會觸發fn
$("input").dblclick(function() { alert("hhhh"); });
3 $(selector).focus():獲得焦點事件
4 $(selector).blur():失去焦點事件
5?$(selector).chang():發生改變
6?$(selector).mousover:鼠標放上
7?$(selector).mouseout:鼠標離開
8?$(selector).mousedown:鼠標抬起
9?$(selector).mouseup:鼠標移動
10?$(selector).mousemove:鼠標移動
js中的事件都帶有on,而jq沒有
鼠標移動案例
事件處理
1? bind("action",fn) 綁定,所以版本都支持
2 如果多個事件:bind({"mouseover":fn1,"mouseout":fn2});
3 unbind("action")解除綁定,沒有參數意味著全部解除
$("div").unbind();
只解除一個:$("div").unbind("mouseout");
4?on:也是綁定(同上)
$(select).on("action",function(){});
5?off:解綁
6?one:綁定事件只會執行一次
$("#d3").one("click",function(){ alert("one"); });
bind和on是重點
查找
1 $(selector).parent(),查找父元素
$("p").parent().css("background":"red");
2 $(selector).find(a);在selector中找a元素
$("div").find(‘p‘).css({background:"red"});
總結
以上是生活随笔為你收集整理的jq父级绑定事件的意义_jq——事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: threejs 绘制球体_ThreeJs
- 下一篇: python tcp server分包_