第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

請(qǐng)問mouseenter不是不支持冒泡嗎,為什么$("input").trigger("mouseenter")可以觸發(fā)事件呢?

<!DOCTYPE?html>
<html>

<head>
????<meta?http-equiv="Content-type"?content="text/html;?charset=utf-8"?/>
????<title></title>
????<style>
????????.left?div,
????????.right?div?{
????????????width:?500px;
????????????height:?50px;
????????????padding:?5px;
????????????margin:?5px;
????????????float:?left;
????????????border:?1px?solid?#ccc;
????????}

????????.left?div?{
????????????background:?#bbffaa;
????????}

????????.right?div?{
????????????background:?yellow;
????????}
????</style>
????<script?src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
????</script>
</head>

<body>
<h2>自定義事件triggerHandler</h2>
<div?class="left">
????<div?id="accident">
????????<a>triggerHandler事件</a>
????????<form?name="input"?action=""?method="get">
??????????<input?type="text"?value="momomo">
????????</form>
????</div>
????<button>事件冒泡,觸發(fā)瀏覽器默認(rèn)聚焦行為</button><br><br>
????<button>不會(huì)冒泡,不觸發(fā)瀏覽器默認(rèn)聚焦行為</button>
</div>
<script?type="text/javascript">

????//給input綁定一個(gè)聚焦事件
????var?n=0;
????$("#accident").on("mouseenter",function(event,title)?{
????????title=title||"默認(rèn)";
????????$("input").val(++n);
????});

????$("#accident").on("click",function(e)?{
????????alert("trigger觸發(fā)的事件會(huì)在?DOM?樹中向上冒泡");
????});
????//trigger觸發(fā)focus
????$("button:first").click(function()?{
????????$("a").trigger("click");
????????$("input").trigger("mouseenter","傳遞");
????});

????//triggerHandler觸發(fā)focus
????$("button:last").click(function()?{
????????$("a").triggerHandler("click");
????????$("input").triggerHandler("mouseenter","沒有觸發(fā)默認(rèn)聚焦事件");
????});



</script>
</body>

</html>


正在回答

1 回答

在jquery的trigger源碼中:

ontype = type.indexOf( ":" ) < 0 && "on" + type;

.....

// Fire handlers on the event path

i = 0;

while ( ( cur = eventPath[ i++ ] ) && !event.isPropagationStopped() ) {

????lastElement = cur;?

????event.type = i > 1 ?bubbleType :special.bindType || type;

????// jQuery handler

????handle = ( dataPriv.get( cur, "events" ) || {} )[ event.type ] &&dataPriv.get( cur, "handle" );

????if ( handle ) {

????????handle.apply( cur, data );

????}

????// Native handler

????handle = ontype && cur[ ontype ];

????if ( handle && handle.apply && acceptData( cur ) ) {

????????event.result = handle.apply( cur, data );

????if ( event.result === false ) {

????????event.preventDefault();

????}

}

type 是事件類型。

eventPath就是從target 到window對(duì)象 的一條路徑。

當(dāng)event.isPropagationStopped() 為假時(shí),會(huì)遍歷eventPath,調(diào)用每個(gè)符合的jquery處理器。


從源碼上知道, type='mouseenter' ?ontype = 'onmouseenter'。必然分別調(diào)用Jquery,原生接口中的處理函數(shù)。

在原生接口中,對(duì)應(yīng)event[ontype]

jquery接口中,對(duì)應(yīng)dataPri.get(cur,'events')[type] ?或者dataPriv.get(cur,'handle') 。

而elem.on() 函數(shù)的調(diào)用:elem.on() -> jquery.on() -> event.add() 最終添加到隊(duì)列中。




0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

DeppSparrow 提問者

非常感謝!
2017-12-29 回復(fù) 有任何疑惑可以回復(fù)我~
#2

tobeyous

看不懂
2018-02-22 回復(fù) 有任何疑惑可以回復(fù)我~
#3

qq_演繹陌路離傷_3 回復(fù) tobeyous

求也看不懂,你說說你會(huì)啥
2018-05-03 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

請(qǐng)問mouseenter不是不支持冒泡嗎,為什么$("input").trigger("mouseenter")可以觸發(fā)事件呢?

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)