$("input").trigger("focus", "觸發(fā)聚焦事件");//觸發(fā)了原生的獲得焦點,參數(shù)不會傳遞?
$("input").triggerHandler("focus","沒有觸發(fā)默認(rèn)聚焦事件");//沒有觸發(fā)聚焦事件?
$("input").triggerHandler("focus","沒有觸發(fā)默認(rèn)聚焦事件");//沒有觸發(fā)聚焦事件?
2018-05-13
$("html").click(function() {
$("#msg").html( $("#msg").html() + "<p>html元素被單擊</p>");
});
再加個html繼續(xù)冒泡
$("#msg").html( $("#msg").html() + "<p>html元素被單擊</p>");
});
再加個html繼續(xù)冒泡
2018-05-13
$("ul").on('click',function(e){
if(this === e.target) return;
alert('觸發(fā)的元素是內(nèi)容是: ' + e.target.textContent)
})
可以把點擊ul的alert去掉
$("ul").on('click' ,function(e){
alert(this);
alert('觸發(fā)的元素是內(nèi)容是: ' + e.target.textContent)
})
去掉了ul的click事件反應(yīng)
if(this === e.target) return;
alert('觸發(fā)的元素是內(nèi)容是: ' + e.target.textContent)
})
可以把點擊ul的alert去掉
$("ul").on('click' ,function(e){
alert(this);
alert('觸發(fā)的元素是內(nèi)容是: ' + e.target.textContent)
})
去掉了ul的click事件反應(yīng)
2018-05-13
把第二n++去掉
off和unbind一樣解綁事件用法幾乎一樣,
off后可以jia選擇器off(event [, selector], function)
unbing的源碼也是用的off
off和unbind一樣解綁事件用法幾乎一樣,
off后可以jia選擇器off(event [, selector], function)
unbing的源碼也是用的off
2018-05-13
$('button').click(function () {
$('body').append("<div class='thrid'>click點擊失效</div>");
});
$('body').on('click','.thrid', function(){
alert();
})
這樣可以給div動態(tài)綁定了,要從父節(jié)點中開始找
$('body').append("<div class='thrid'>click點擊失效</div>");
});
$('body').on('click','.thrid', function(){
alert();
})
這樣可以給div動態(tài)綁定了,要從父節(jié)點中開始找
2018-05-13
on可以動態(tài)綁定事件。
比如為自己在js中動態(tài)新創(chuàng)建的div標(biāo)簽綁定click事件,用click失效,用on可以
$('button').click(function () {
$('body').append("<div class='thrid'>click點擊失效</div>");
});
$('.thrid').click(function () {
alert('失效了嗎');
比如為自己在js中動態(tài)新創(chuàng)建的div標(biāo)簽綁定click事件,用click失效,用on可以
$('button').click(function () {
$('body').append("<div class='thrid'>click點擊失效</div>");
});
$('.thrid').click(function () {
alert('失效了嗎');
2018-05-13
mouseout是從當(dāng)前元素上離開就會觸發(fā)(包括子元素),mouseleave是從選中的元素離開觸發(fā)(不包括子元素)。
2018-05-13
<script type="text/javascript">
//綁定一個mousemove事件
//觸發(fā)后修改內(nèi)容
$("html").mousemove(function(e) {
$(this).find('.left p:last').html('移動的(X,Y)位置:(' + e.pageX+","+ e.pageY+")")
})
</script>
測試二這樣,可以整個網(wǎng)頁取坐標(biāo),改為body,可以看到body有多大
//綁定一個mousemove事件
//觸發(fā)后修改內(nèi)容
$("html").mousemove(function(e) {
$(this).find('.left p:last').html('移動的(X,Y)位置:(' + e.pageX+","+ e.pageY+")")
})
</script>
測試二這樣,可以整個網(wǎng)頁取坐標(biāo),改為body,可以看到body有多大
2018-05-13
<p>1</p>
$('p').mousedown(function(e) {
alert(e.target.textContent)
})
//this指向button元素
$("button:eq(1)").mousedown(function() {
$('p').mousedown() //指定觸發(fā)綁定的事件
})
<p>2</p>
測試二,對上面一個p綁定了事件,下面的p沒有綁定事件,是與標(biāo)簽和script出現(xiàn)順序有關(guān)嗎
$('p').mousedown(function(e) {
alert(e.target.textContent)
})
//this指向button元素
$("button:eq(1)").mousedown(function() {
$('p').mousedown() //指定觸發(fā)綁定的事件
})
<p>2</p>
測試二,對上面一個p綁定了事件,下面的p沒有綁定事件,是與標(biāo)簽和script出現(xiàn)順序有關(guān)嗎
2018-05-13
$("button:eq(2)").add(".test3").click(1122, function(e){
alert(e.data)
})
測試三這樣寫好看些add()給div也加了點擊事件
alert(e.data)
})
測試三這樣寫好看些add()給div也加了點擊事件
2018-05-13
$('.aaron').on('click','li',function(e){
alert('觸發(fā)的元素是內(nèi)容是: ' + e.target.textContent)
}) 改成這樣也可以
alert('觸發(fā)的元素是內(nèi)容是: ' + e.target.textContent)
}) 改成這樣也可以
2018-05-08