<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FoxLing - 前端开发 &#187; 阻止</title>
	<atom:link href="http://foxling.org/tag/%e9%98%bb%e6%ad%a2/feed/" rel="self" type="application/rss+xml" />
	<link>http://foxling.org</link>
	<description>不积跬步 无以至千里</description>
	<lastBuildDate>Mon, 05 Jul 2010 16:43:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>阻止Javascript事件冒泡</title>
		<link>http://foxling.org/js-ajax-dom/javascript-cancel-bubble/</link>
		<comments>http://foxling.org/js-ajax-dom/javascript-cancel-bubble/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 23:52:48 +0000</pubDate>
		<dc:creator>FoxLing</dc:creator>
				<category><![CDATA[JS/AJAX/DOM]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[事件冒泡]]></category>
		<category><![CDATA[阻止]]></category>

		<guid isPermaLink="false">http://wp.foxling.cn/as-flex-air/javascript-bubble/</guid>
		<description><![CDATA[工作中偶尔会遇到Javascript冒泡的问题，阻止冒泡的方法：
W3C:stopPropagation()
IE:window.event.cancelBubble = true
运行以下代码，然后注释掉&#8221;//阻止冒泡&#8221;后面那段代码，看看发生的变化。

&#60;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 0 Transitional//EN" "http://www.worg/TR/xhtml1/DTD/xhtml1-transitional.dtd"&#62;
&#60;html xmlns="http://www.worg/1999/xhtml"&#62;
&#60;head&#62;
&#60;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&#62;
&#60;title&#62;Untitled Document&#60;/title&#62;
&#60;style type="text/css"&#62;
div {
	padding:10px;
	border:1px solid #CCC;
}
#d1 {
   width:400px;
}
#msg {
   border-color:#CCC;
   padding:3px;
   margin-bottom:10px;
}
&#60;/style&#62;
&#60;script&#62;
 var isIE = /*@cc_on!@*/!1;
 window.onload = m;
 function m(){
	 for (var i=1; i&#60;6; i++){
		 document.getElementById('d'+i).onmouseover = changeStyle;
		 document.getElementById('d'+i).onmouseout = changeStyle;
	 }
 [...]]]></description>
			<content:encoded><![CDATA[<p>工作中偶尔会遇到Javascript冒泡的问题，阻止冒泡的方法：</p>
<p>W3C:stopPropagation()<br />
IE:window.event.cancelBubble = true</p>
<p>运行以下代码，然后注释掉&#8221;//阻止冒泡&#8221;后面那段代码，看看发生的变化。</p>
<pre>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 0 Transitional//EN" "http://www.worg/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.worg/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;style type="text/css"&gt;
div {
	padding:10px;
	border:1px solid #CCC;
}
#d1 {
   width:400px;
}
#msg {
   border-color:#CCC;
   padding:3px;
   margin-bottom:10px;
}
&lt;/style&gt;
&lt;script&gt;
 var isIE = /*@cc_on!@*/!1;
 window.onload = m;
 function m(){
	 for (var i=1; i&lt;6; i++){
		 document.getElementById('d'+i).onmouseover = changeStyle;
		 document.getElementById('d'+i).onmouseout = changeStyle;
	 }
 }
 function changeStyle(e){
	 e = e || window.event;
	 var msg = document.getElementById('msg');
	 if (e.type == 'mouseover'){
		 this.style.borderColor = '#FF0000';
		 msg.innerHTML = '你当前鼠标经过的DIV ID：' + this.id;
	 }else if(e.type == 'mouseout'){
		 this.style.borderColor = '#CCCCCC';
		 msg.innerHTML = '鼠标状态';
	 }    

	 //阻止冒泡
	 if (isIE){
		 e.cancelBubble = true;
	 }else{
		 e.stopPropagation();
	 }
 }
 &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="msg"&gt;鼠标状态&lt;/div&gt;
&lt;div id="d1"&gt;ID:d1
   &lt;div id="d2"&gt;ID:d2
	   &lt;div id="d3"&gt;ID:d3
		   &lt;div id="d4"&gt;ID:d4
			   &lt;div id="d5"&gt;ID:d5 &lt;/div&gt;
		   &lt;/div&gt;
	   &lt;/div&gt;
   &lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://foxling.org/js-ajax-dom/javascript-cancel-bubble/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
