鐐瑰嚮椤甸潰鍏跺畠鍦版柟闅愯棌鏌愪釜div鐨勪袱绉嶆€濊矾
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鐐瑰嚮椤甸潰鍏跺畠鍦版柟闅愯棌鏌愪釜div鐨勪袱绉嶆€濊矾相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%ba%8b%e4%bb%b6%e7%bb%91%e5%ae%9a' title='浜嬩欢缁戝畾'>浜嬩欢缁戝畾 || function 寰幆 dom parent 瀹屾垚 鏂瑰紡 tar
鎬濊矾涓€ 绗竴绉嶆€濊矾鍒嗕袱姝?br /> 绗?姝ワ細瀵筪ocument鐨刢lick浜嬩欢缁戝畾浜嬩欢澶勭悊绋嬪簭锛屼娇鍏堕殣钘忚div
绗?姝ワ細瀵筪iv鐨刢lick浜嬩欢缁戝畾浜嬩欢澶勭悊绋嬪簭锛岄樆姝簨浠跺啋娉★紝闃叉鍏跺啋娉″埌document锛岃€岃皟鐢╠ocument鐨刼nclick鏂规硶闅愯棌浜嗚div
$(document).bind(鈥榗lick鈥?function(){
$(鈥?test鈥?.hide();
});
$(鈥?test鈥?.bind(鈥榗lick鈥?function(e){
stopPropagation(e);
});
function stopPropagation(e) {
if (e.stopPropagation) e.stopPropagation();
else e.cancelBubble = true;
}
杩欐牱褰撶偣鍑婚〉闈㈤潪div鍖哄煙鐨勬椂鍊欙紝鐩存帴鎴栧眰灞傚啋娉′細璋冪敤document鐨刼nclick鏂规硶锛岄殣钘忚div锛岃€岀偣鍑籨iv鎴栧叾瀛愬厓绱犵殑鏃跺€欙紝浜嬩欢鎬讳細鍐掓场鐨刣iv鏈韩锛岃繖鏃跺€欎細闃绘浜嬩欢缁х画鍐掓场锛屼笉浼氳皟鐢╠oument鐨刼nclick鏂规硶鑷翠娇div琚殣钘忥紝浠庤€屽畬鎴愪簡鎴戜滑鐨勯渶姹傘€?br /> $(document).bind(鈥榗lick鈥?function(e){ $(鈥?test鈥?.hide(); //鐐瑰嚮鐨勪笉鏄痙iv鎴栧叾瀛愬厓绱?/span> 杩欐牱褰撶偣鍑婚〉闈换浣曞湴鏂圭殑鏃跺€欓兘浼氬眰灞傚啋娉¤嚦document鐨刢lick浜嬩欢锛屼簨浠跺鐞嗙▼搴忎細鍒ゆ柇浜嬩欢婧愭槸鍚︿负id==test鐨刣iv鎴栧叾瀛愬厓绱狅紝濡傛灉鏄柟娉時eturn锛屽惁鍒欓殣钘忚div锛屼篃鑳藉瀹炵幇鎴戜滑鐨勯渶姹傘€?/p>
以上是关于鐐瑰嚮椤甸潰鍏跺畠鍦版柟闅愯棌鏌愪釜div鐨勪袱绉嶆€濊矾的主要内容,如果未能解决你的问题,请参考以下文章 SEO浼樺寲锛氭祬鏋愰潤鎬佸寲椤甸潰瀵逛簬缃戠珯浼樺寲鐨勫奖鍝嶆槸浠€涔堬紵 uiautomatorviewer杩炴帴鏈哄櫒鐐瑰嚮鎶ラ敊Unexpected error while obtaining UI hierarchy
鎬濊矾浜?/strong>
鎴戜滑涔嬪墠鎻愬埌锛屽湪瑙﹀彂DOM涓婄殑鏌愪釜浜嬩欢鐨勬椂鍊欎細浜х敓涓€涓簨浠跺璞vent锛岃繖涓璞″寘鍚潃鎵€鏈変笌浜嬩欢鏈夊叧鐨勪俊鎭紝鍖呮嫭浜х敓浜嬩欢鐨勫厓绱犮€佷簨浠剁被鍨嬬瓑鐩稿叧淇℃伅锛屾€濊矾涓€涓璬iv鐨刢lick浜嬩欢澶勭悊绋嬪簭浼犲叆鐨勫弬鏁板氨鏄繖涓猠vent瀵硅薄銆傝闂甀E涓殑event瀵硅薄鏈夊嚑绉嶄笉鍚岀殑鏂瑰紡锛屽彇鍐充簬鎸囧畾浜嬩欢澶勭悊绋嬪簭鐨勬柟娉曘€傜洿鎺ヤ负DOM鍏冪礌娣诲姞浜嬩欢澶勭悊绋嬪簭鏃讹紝event瀵硅薄浣滀负window瀵硅薄鐨勪竴涓睘鎬у瓨鍦ㄣ€?br />
event瀵硅薄鍖呭惈浜嗕竴涓噸瑕佸睘鎬э細target(W3C)/srcElement(IE)锛岃繖涓睘鎬ф爣璇嗕簡瑙﹀彂浜嬩欢鐨勫師濮嬪厓绱狅紝鎬濊矾浜屽氨鏄鍒╃敤杩欎釜灞炴€с€傛垜浠彲浠ョ洿鎺ュdocument鐨刢lick浜嬩欢缁戝畾浜嬩欢澶勭悊绋嬪簭锛屽湪浜嬩欢澶勭悊绋嬪簭涓垽璇讳簨浠舵簮鏄惁涓篿d==test鐨刣iv鍏冪礌鎴栧叾瀛愬厓绱狅紝濡傛灉鏄垯鏂规硶return涓嶅仛鎿嶄綔锛屽鏋滀笉鏄垯闅愯棌璇iv銆?/p>
var e = e || window.event; //娴忚鍣ㄥ吋瀹规€?/span>
var elem = e.target || e.srcElement;
while (elem) { //寰幆鍒ゆ柇鑷宠窡鑺傜偣锛岄槻姝㈢偣鍑荤殑鏄痙iv瀛愬厓绱?/span>
if (elem.id && elem.id==鈥榯est鈥? {
return;
}
elem = elem.parentNode;
}
});