<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="ARTICLE @ XOOPS powered by FeedCreator" -->
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="http://waterlily-lsl.com//modules/article/xml.php/rdf/178/c2">
        <title>睡蓮‧池水間 :: 文章</title>
        <description>文章XML</description>
        <link>http://waterlily-lsl.com/modules/article/view.article.php/178/c2</link>
        <image rdf:resource="http://waterlily-lsl.com/modules/article/images/logo.png" />
       <dc:date>2012-02-10T23:55:12+02:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="http://waterlily-lsl.com/modules/article/view.article.php/178/c2"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="http://waterlily-lsl.com/modules/article/images/logo.png">
        <title>睡蓮‧池水間 :: 文章</title>
        <link>http://waterlily-lsl.com/modules/article/</link>
        <url>http://waterlily-lsl.com/modules/article/images/logo.png</url>
    </image>
    <item rdf:about="http://waterlily-lsl.com/modules/article/view.article.php/178/c2">
        <dc:format>text/html</dc:format>
        <dc:date>2009-05-26T22:52:49+02:00</dc:date>
        <dc:source>http://waterlily-lsl.com/modules/article/</dc:source>
        <dc:creator>睡蓮</dc:creator>
        <title>Firefox和IE之間7個JavaScript的差異</title>
        <link>http://waterlily-lsl.com/modules/article/view.article.php/178/c2</link>
        <description>類別: 語言集&lt;br /&gt;來源: (http://www.impressivewebs.com/7-javascript-differences-between-firefox-ie/)&lt;span style=&quot;background:#392337;border:1px solid #6a4466;padding:2px;margin:5px 0 30px;font-size:13px&quot;&gt;譯者：糖伴西紅柿&lt;/span&gt;
&lt;span style=&quot;background:#392337;border:1px solid #6a4466;padding:2px;margin:0 0 5px;font-size:13px&quot;&gt;譯文出處：&amp;#119;ww.qianduan.net/between-firefox-and-ie-differences-7-javascript.html&lt;/span&gt;
&lt;br /&gt;&lt;br /&gt;

盡管 JavaScript 歷史上使用冗長而令人生厭的代碼塊來標的特定瀏覽器的時期已經結束了，但是偶爾使用一些簡單的代碼塊和對象檢測來確保一些代碼在用戶機器上正常工作依然是必要的。&lt;br /&gt;&lt;br /&gt;

這篇文章中，我會略述一下 Internet Explorer 和 Firefox 在 JavaScript 語法上不同的 7 個方面。&lt;br /&gt;&lt;br /&gt;

&lt;strong class=&quot;A_strong&quot;&gt;1. CSS “float” 屬性&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;

獲取給定對象的特定 CSS 屬性的基本語法是 object.style 屬性，而且有連字符的屬性要用駱駝命名法來代替。例如，獲取一個 ID 為 “header” 的 div 的 background-color 屬性，我們要用如下語法：&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;document.getElementById(&amp;quot;header&amp;quot;).style.borderBottom= &amp;quot;1px solid #ccc&amp;quot;;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

但是由於 “float” 是 JavaScript 的保留詞，我們就無法使用 object.style.float 來獲取 “float” 屬性了。以下是我們在兩種瀏覽器中的使用的方法：&lt;br /&gt;&lt;br /&gt;

IE 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;document.getElementById(&amp;quot;header&amp;quot;).style.styleFloat = &amp;quot;left&amp;quot;;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

Firefox 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;document.getElementById(&amp;quot;header&amp;quot;).style.cssFloat = &amp;quot;left&amp;quot;;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

&lt;strong class=&quot;A_strong&quot;&gt;2. 元素的計算樣式&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;

通過使用上述的 object.style.property， JavaScript 可以很容易的獲取和修改對象的設定 CSS 樣式。但是這一語法的局限在於，它只能取得內聯在 HTML 裡的樣式，或者直接使用 JavaScript 設定的樣式。style 對象不能獲取使用外部樣式表設定的樣式。為了獲取對象的“計算樣式”，我們使用以下代碼：&lt;br /&gt;&lt;br /&gt;

IE 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myObject = document.getElementById(&amp;quot;header&amp;quot;);   
var myStyle = myObject.currentStyle.backgroundColor;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

Firefox 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myObject = document.getElementById(&amp;quot;header&amp;quot;);
var myComputedStyle = document.defaultView.getComputedStyle(myObject, null);
var myStyle = myComputedStyle.backgroundColor;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

&lt;strong class=&quot;A_strong&quot;&gt;3. 獲取元素的”class”屬性&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;

類似於”float”屬性的情況，這兩種瀏覽器使用不同的 JavaScript 方法來獲取這個屬性。&lt;br /&gt;&lt;br /&gt;

IE 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myObject = document.getElementById(&amp;quot;header&amp;quot;);
var myAttribute = myObject.getAttribute(&amp;quot;className&amp;quot;);
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

Firefox 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myObject = document.getElementById(&amp;quot;header&amp;quot;);
var myAttribute = myObject.getAttribute(&amp;quot;class&amp;quot;);
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

&lt;strong class=&quot;A_strong&quot;&gt;4. 獲取 label 標籤的 “for” 屬性&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;

和 3. 一樣，使用 JavaScript獲取 label 的 “for” 屬性也有不同語法。&lt;br /&gt;&lt;br /&gt;

IE 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myObject = document.getElementById(&amp;quot;myLabel&amp;quot;);
var myAttribute = myObject.getAttribute(&amp;quot;htmlFor&amp;quot;);
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

Firefox 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myObject = document.getElementById(&amp;quot;myLabel&amp;quot;);
var myAttribute = myObject.getAttribute(&amp;quot;for&amp;quot;);
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

對於 setAtrribute 方法來說也是同樣的語法。&lt;br /&gt;&lt;br /&gt;

&lt;strong class=&quot;A_strong&quot;&gt;5. 獲取光標位置&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;

獲取元素的光標位置比較少見，如果需要這麽做，IE 和 Firefox 的語法也是不同的。這個示例代碼是相當基礎的，一般用作許多複雜事件處理的一部分，這裡僅用來描述差異。需要注意的是，IE 中的結果和 Firefox 中是不同的，因此這個方法有些問題。通常，這個差異可以通過獲取 “滾動位置” 來補償 － 但那是另外一篇文章的課題了。&lt;br /&gt;&lt;br /&gt;

IE 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myCursorPosition = [0, 0];
myCursorPosition[0] = event.clientX;
myCursorPosition[1] = event.clientY;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

Firefox 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myCursorPosition = [0, 0];
myCursorPosition[0] = event.pageX;
myCursorPosition[1] = event.pageY;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

&lt;strong class=&quot;A_strong&quot;&gt;6. 獲取視窗或瀏覽器窗口的尺寸&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;

有時需要找出瀏覽器的有效窗口空間的尺寸，一般成為“視窗”。&lt;br /&gt;&lt;br /&gt;

IE 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myBrowserSize = [0, 0];
myBrowserSize[0] = document.documentElement.clientWidth;
myBrowserSize[1] = document.documentElement.clientHeight;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

Firefox 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myBrowserSize = [0, 0];
myBrowserSize[0] = window.innerWidth;
myBrowserSize[1] = window.innerHeight;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

&lt;strong class=&quot;A_strong&quot;&gt;7. Alpha 透明&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;

嗯，這其實不是 JavaScript 的語法項目 – alpha 透明是通過 CSS 來設置的。但是當對象通過 JavaScript 設置為淡入淡出時，這就需要通過獲取 CSS 的 alpha 設定來實現，一般是在循環內部。要通過以下 JavaScript 來改變 CSS 代碼：&lt;br /&gt;&lt;br /&gt;

IE 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
#myElement {
filter: alpha(opacity=50);
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

Firefox 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
#myElement {
opacity: 0.5;
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

要使用 JavaScript 獲取這些值，需要使用 style 對象：&lt;br /&gt;&lt;br /&gt;

IE 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myObject = document.getElementById(&amp;quot;myElement&amp;quot;);
myObject.style.filter = &amp;quot;alpha(opacity=80)&amp;quot;;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

Firefox 語法：
&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
var myObject = document.getElementById(&amp;quot;myElement&amp;quot;);
myObject.style.opacity = &amp;quot;0.5&amp;quot;;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;

當然，已經說到了，一般是在循環中間來改變 opcity/alpha，來創建動畫效果，但這是個簡單的例子，只是為了明白地描述方法是如何實現地。&lt;br /&gt;</description>
    </item>
</rdf:RDF>

