<?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"
	>

<channel>
	<title>缘由心生</title>
	<atom:link href="http://www.welcome58.cn/feed" rel="self" type="application/rss+xml" />
	<link>http://www.welcome58.cn</link>
	<description>前端技术（Xhtml/Css/javascript/UI/...）学习</description>
	<pubDate>Wed, 03 Mar 2010 03:39:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>JavaScript中的作用域</title>
		<link>http://www.welcome58.cn/archives/154</link>
		<comments>http://www.welcome58.cn/archives/154#comments</comments>
		<pubDate>Wed, 03 Mar 2010 03:39:17 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Javascript/Ajax/jQuery]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=154</guid>
		<description><![CDATA[原文：http://www.digital-web.com/articles/scope_in_javascript/
作用域（scope）是JavaScript语言的基石之一，在构建复杂程序时也可能是最令我头痛的东西。记不清多少次在函数之间传递控制后忘记 this它会将局部作用域增加到它所定义的作用域链内。JavaScript通过作用域链的局部向全局攀升方式，在特定的上下文中解析标识符。这表示，本级变量会优先于作用域链内上一级拥有相同名字的变量。显而易见，当我的好友们一起谈论”Mike West”（本文原作者）时，他们说的就是我，而非bluegrass singer 或是Duke professor, 尽管（按理说）后两者著名多了。
<span class="readmore"><a href="http://www.welcome58.cn/archives/154" title="JavaScript中的作用域" target="_blank">阅读全文——共7287字</a></span>]]></description>
			<content:encoded><![CDATA[<p>原文：<a href="http://www.digital-web.com/articles/scope_in_javascript/"><span style="color: #27527d;">http://www.digital-web.com/articles/scope_in_javascript/</span></a></p>
<p>作用域（<a href="http://en.wikipedia.org/wiki/Scope_%28programming%29"><span style="color: #27527d;">scope</span></a>）是JavaScript语言的基石之一，在构建复杂程序时也可能是最令我头痛的东西。记不清多少次在函数之间传递控制后忘记<code><span style="font-size: small;"> this</span></code>它会将局部作用域增加到它所定义的作用域链内。JavaScript通过作用域链的局部向全局攀升方式，在特定的上下文中解析标识符。这表示，本级变量会优先于作用域链内上一级拥有相同名字的变量。显而易见，当我的好友们一起谈论”Mike West”（本文原作者）时，他们说的就是我，而非<a href="http://www.mikewest.net/"><span style="color: #27527d;">bluegrass singer</span></a> 或是<a href="http://www.isds.duke.edu/~mw/"><span style="color: #27527d;">Duke professor</span></a>, 尽管（按理说）后两者著名多了。</p>
<p>让我们看些例子来探索这些含义：</p>
<pre><code><span style="font-size: small;">&lt;script type=&#8221;text/javascript&#8221;&gt;
 var ima_celebrity = &#8220;Everyone can see me! I&#8217;m famous!&#8221;,
  the_president = &#8220;I&#8217;m the decider!&#8221;;

 function pleasantville() {
  var the_mayor = &#8220;I rule Pleasantville with an iron fist!&#8221;,
   ima_celebrity = &#8220;All my neighbors know who I am!&#8221;;

  function lonely_house() {
   var agoraphobic = &#8220;I fear the day star!&#8221;,
    a_cat = &#8220;Meow.&#8221;;
  }
 }
&lt;/script&gt;</span></code></pre>
<p>我们的全明星，<code><span style="font-size: small;">ima_celebrity</span></code>, 家喻户晓（所有人都认识她）。她在政治上积极活跃，敢于在一个相当频繁的基层上叫嚣总统（即<code><span style="font-size: small;">the_president</span></code>）。她会为碰到的每一个人签名和回答问题。就是说，她不会跟她的粉丝有私下的联系。她相当清楚粉丝们的<em>存在 </em>并有他们自己某种程度上的个人生活，但也可以肯定的是，她并不知道粉丝们在干嘛，甚至连粉丝的名字都不知道。</p>
<p>而在欢乐市（<code><span style="font-size: small;">pleasantville</span></code>）内，市长（<code><span style="font-size: small;">the_mayor</span></code>）是众所周知的。她经常在她的城镇内散步，跟她的选民聊天、握手并亲吻小孩。因为欢乐市（<code><span style="font-size: small;">pleasantville</span></code>）还算比较大且重要的邻居，市长在她办公室内放置一台红色电话，它是一条可以直通总统的7×24热线。她还可以看到市郊外山上的孤屋（<code><span style="font-size: small;">lonely_house</span></code>），但从不在意里面住着的是谁。</p>
<p>而孤屋（lonely_house）是一个自我的世界。旷恐患者时常在里面囔囔自语，玩纸牌和喂养一个小猫（<code><span style="font-size: small;">a_cat</span></code>）。他偶尔会给市长（<code><span style="font-size: small;">the_mayor</span></code>）打电话咨询一些本地的噪音管制，甚至在本地新闻看到<code><span style="font-size: small;">ima_celebrity</span></code>后会写些粉丝言语给她（当然，这是<code><span style="font-size: small;">pleasantville</span></code>内的<code><span style="font-size: small;">ima_celebrity</span></code>）。</p>
<h2><code><span style="font-size: small;">this</span></code>? 那是虾米？</h2>
<p>每一个运行上下文除了建立一个作用域链外，还提供一个名为<code><span style="font-size: small;">this</span></code>的关键字。它的普遍用法是，<code><span style="font-size: small;">this</span></code>作为一个独特的功能，为邻里们提供一个可访问到它的途径。但总是依赖于这个行为并不可靠：取决于我们如何进入一个特定邻居的具体情况，<code><span style="font-size: small;">this</span></code>表示的完全可能是其他东西。事实上，<em>我们如何进去邻居家</em>本身，通常恰恰就是<code><span style="font-size: small;">this</span></code>所指。有四种情形值得特别注意：</p>
<ul>
<li>
<h3>呼叫对象的方法</h3>
<p>在经典的面向对象编程中，我们需要识别和引用当前对象。<code><span style="font-size: medium;">this</span></code>极好地扮演了这个角色，为我们的对象提供了自我查找的能力，并指向它们本身的属性。</p>
<pre><code><span style="font-size: medium;">&lt;script type=&#8221;text/javascript&#8221;&gt;
  var deep_thought = {
   the_answer: 42,
   ask_question: function () {
    return this.the_answer;
   }
  };

  var the_meaning = deep_thought.ask_question();
&lt;/script&gt;</span></code></pre>
<p>这个例子建立了一个名为<code><span style="font-size: medium;">deep_thought</span></code>的对象，设置其属性<code><span style="font-size: medium;"> the_answer</span></code>为42，并创建了一个名为<code><span style="font-size: medium;">ask_question</span></code> 的方法（method）。当<code><span style="font-size: medium;">deep_thought.ask_question()</span></code>执行时， JavaScript为函数的呼叫建立了一个运行上下文，通过”<code><span style="font-size: medium;">.</span></code>“运算符把<code><span style="font-size: medium;">this</span></code>指向被引用的对象，在此是<code><span style="font-size: medium;">deep_thought</span></code>这个对象。之后这个方法就可以通过<code><span style="font-size: medium;">this</span></code>在镜子中找到它自身的属性，返回保存在 <code><span style="font-size: medium;">this.the_answer</span></code>中的值：42。</li>
<li>
<h3>构造函数</h3>
<p>类似地，当定义一个作为构造器的使用<code><span style="font-size: medium;">new</span></code>关键字的函数时，<code><span style="font-size: medium;">this</span></code>可以用来引用刚创建的对象。让我们重写一个能反映这个情形的例子：</p>
<pre><code><span style="font-size: medium;">&lt;script type=&#8221;text/javascript&#8221;&gt;
  function BigComputer(answer) {
   this.the_answer = answer;
   this.ask_question = function () {
    return this.the_answer;
   }
  }

  var deep_thought = new BigComputer(42);
  var the_meaning = deep_thought.ask_question();
&lt;/script&gt;</span></code></pre>
<p>我们编写一个函数来创建<code><span style="font-size: medium;">BigComputer</span></code>对象，而不是直白地创建<code><span style="font-size: medium;"> deep_thought</span></code>对象，并通过<code><span style="font-size: medium;">new</span></code>关键字实例化<code><span style="font-size: medium;">deep_thought</span></code>为一个实例变量。当<code><span style="font-size: medium;">new BigComputer()</span></code>被执行，后台透明地创建了一个崭新的对象。呼叫<code><span style="font-size: medium;">BigComputer</span></code>后，它的<code><span style="font-size: medium;">this</span></code>关键字被设置为指向新对象的引用。这个函数可以在<code><span style="font-size: medium;">this</span></code>上设置属性和方法，最终它会在<code><span style="font-size: medium;">BigComputer</span></code>执行后透明地返回。</p>
<p>尽管如此，需要注意的是，那个<code><span style="font-size: medium;">deep_thought.the_question()</span></code>依然可以像从前一样执行。那这里发生了什么事？为何<code><span style="font-size: medium;">this</span></code>在<code><span style="font-size: medium;">the_question</span></code>内与BigComputer内会有所不同？简单地说，我们是通过<code><span style="font-size: medium;">new</span></code><em>进入</em><code><span style="font-size: medium;">BigComputer</span></code>的，所以<code><span style="font-size: medium;">this</span></code>表示“新（new）的对象”。在另一方面，我们通过<code><span style="font-size: medium;"> deep_thought</span></code><em>进入</em><code><span style="font-size: medium;">the_question</span></code>，所以当我们执行该方法时，<code><span style="font-size: medium;">this</span></code>表示 “<code><span style="font-size: medium;">deep_thought</span></code>所引用的对象”。<code><span style="font-size: medium;">this</span></code>并不像其他的变量一样从作用域链中读取，而是在上下文的基础上，在上下文中<em>重置</em>。</li>
<li>
<h3>函数呼叫</h3>
<p>假如没有任何相关对象的奇幻东西，我们只是呼叫一个普通的、常见的函数，在这种情形下<code><span style="font-size: medium;">this</span></code>表示的又是什么呢？</p>
<pre><code><span style="font-size: medium;">&lt;script type=&#8221;text/javascript&#8221;&gt;
  function test_this() {
   return this;
  }
  var i_wonder_what_this_is = test_this();
&lt;/script&gt;</span></code></pre>
<p>在这样的场合，我们并不通过<code><span style="font-size: medium;">new</span></code>来提供上下文，也不会以某种对象形式在背后偷偷提供上下文。在此， <code><span style="font-size: medium;">this</span></code>默认下尽可能引用最全局的东西：对于网页来说，这就是<code><span style="font-size: medium;"> window</span></code>对象。</li>
<li>
<h3>事件处理函数</h3>
<p>比普通函数的呼叫更复杂的状况，先假设我们使用函数去处理的是一个<code><span style="font-size: medium;">onclick</span></code>事件。当事件触发我们的函数运行，此处的<code><span style="font-size: medium;">this</span></code>表示的是什么呢？不凑巧，这个问题不会有简单的答案。</p>
<p>如果我们写的是行内（inline）事件处理函数，<code><span style="font-size: medium;">this</span></code>引用的是全局<code><span style="font-size: medium;">window</span></code>对象：</p>
<pre><code><span style="font-size: medium;">&lt;script type=&#8221;text/javascript&#8221;&gt;
  function click_handler() {
   alert(this); // 弹出 window 对象
  }
&lt;/script&gt;
 &#8230;
&lt;button id=&#8217;thebutton&#8217; onclick=&#8217;click_handler()&#8217;&gt;Click me!&lt;/button&gt;</span></code></pre>
<p>但是，如果我们通过JavaScript来添加事件处理函数，<code><span style="font-size: medium;">this</span></code>引用的是生成该事件的DOM元素。（注意：此处的事件处理非常简洁和易于阅读，但其他的就别有洞天了。请使用<a href="http://dean.edwards.name/weblog/2005/10/add-event2/"><span style="color: #27527d;">真正的addEvent函数</span></a>取而代之）：</p>
<pre><code><span style="font-size: medium;">&lt;script type=&#8221;text/javascript&#8221;&gt;
  function click_handler() {
   alert(this); // 弹出按钮的DOM节点
  }

  function addhandler() {
   document.getElementById(&#8217;thebutton&#8217;).onclick = click_handler;
  }

  window.onload = addhandler;
&lt;/script&gt;
 &#8230;
&lt;button id=&#8217;thebutton&#8217;&gt;Click me!&lt;/button&gt;</span></code></pre>
</li>
</ul>
<h2>复杂情况</h2>
<p>让我们来短暂地运行一下这个最后的例子。我们需要询问<code><span style="font-size: small;">deep_thought</span></code>一个问题，如果不是直接运行<code><span style="font-size: small;">click_handler</span></code>而是通过点击按钮的话，那会发生什么事情？解决此问题的代码貌似十分直接，我们可能会这样做：</p>
<pre><code><span style="font-size: small;">&lt;script type=&#8221;text/javascript&#8221;&gt;
 function BigComputer(answer) {
  this.the_answer = answer;
  this.ask_question = function () {
   alert(this.the_answer);
  }
 }

 function addhandler() {
  var deep_thought = new BigComputer(42),
   the_button = document.getElementById(&#8217;thebutton&#8217;);

  the_button.onclick = deep_thought.ask_question;
 }

 window.onload = addhandler;
&lt;/script&gt;</span></code></pre>
<p>很完美吧？想象一下，我们点击按钮，<code><span style="font-size: small;">deep_thought.ask_question</span></code>被执行，我们也得到了“42”。但是为什么浏览器却给我们一个<code><span style="font-size: small;">undefined</span></code>? 我们错在何处？</p>
<p>其实问题显而易见：我们给<code><span style="font-size: small;">ask_question</span></code>传递一个引用，它作为一个事件处理函数来执行，与作为对象方法来运行的上下文并不一样。简而言之，<code><span style="font-size: small;">ask_question</span></code>中的<code><span style="font-size: small;"> this</span></code>关键字指向了产生事件的DOM元素，而不是在<code><span style="font-size: small;">BigComputer</span></code>的对象中。DOM元素并不存在一个<code><span style="font-size: small;">the_answer</span></code>属性，所以我们得到的是 <code><span style="font-size: small;">undefined</span></code>而不是”42″. <code><span style="font-size: small;">setTimeout</span></code>也有类似的行为，它在延迟函数执行的同时跑到了一个全局的上下文中去了。</p>
<p>这个问题会在程序的所有角落时不时突然冒出，如果不细致地追踪程序的每一个角落的话，还是一个非常难以排错的问题，尤其在你的对象有跟DOM元素或者<code><span style="font-size: small;">window</span></code>对象同名属性的时候。</p>
<h2>使用<code><span style="font-size: small;">.apply()</span></code>和<code><span style="font-size: small;">.call()</span></code>掌控上下文</h2>
<p>在点击按钮的时候，我们真正需要的是能够咨询<code><span style="font-size: small;">deep_thought</span></code>一个问题，更进一步说，我们真正需要的是，在应答事件和<code><span style="font-size: small;">setTimeout</span></code>的呼叫时，能够在自身的本原上下文中呼叫对象的方法。有两个鲜为人知的JavaScript方法，<code><span style="font-size: small;">apply</span></code>和<code><span style="font-size: small;">call</span></code>，在我们执行函数呼叫时，可以曲线救国帮我们达到目的，允许我们手工覆盖<code><span style="font-size: small;">this</span></code>的默认值。我们先来看<code><span style="font-size: small;">call</span></code>：</p>
<pre><code><span style="font-size: small;">&lt;script type=&#8221;text/javascript&#8221;&gt;
 var first_object = {
  num: 42
 };
 var second_object = {
  num: 24
 };

 function multiply(mult) {
  return this.num * mult;
 }

 multiply.call(first_object, 5); // 返回 42 * 5
 multiply.call(second_object, 5); // 返回 24 * 5
&lt;/script&gt;</span></code></pre>
<p>在这个例子中，我们首先定义了两个对象，<code><span style="font-size: small;">first_object</span></code>和<code><span style="font-size: small;">second_object</span></code>，它们分别有自己的<code><span style="font-size: small;">num</span></code>属性。然后定义了一个<code><span style="font-size: small;">multiply</span></code>函数，它只接受一个参数，并返回该参数与<code><span style="font-size: small;">this</span></code>所指对象的<code><span style="font-size: small;">num</span></code>属性的乘积。如果我们呼叫函数自身，返回的答案极大可能是<code><span style="font-size: small;">undefined</span></code>，因为全局<code><span style="font-size: small;">window</span></code>对象并没有一个<code><span style="font-size: small;">num</span></code>属性除非有明确的指定。我们需要一些途径来告诉<code><span style="font-size: small;">multiply</span></code>里面的<code><span style="font-size: small;">this</span></code>关键字应该引用什么。而<code><span style="font-size: small;">multiply</span></code>的<code><span style="font-size: small;">call</span></code>方法正是我们所需要的。</p>
<p><code><span style="font-size: small;">call</span></code>的第一个参数定义了在业已执行的函数内<code><span style="font-size: small;">this</span></code>的所指对象。其余的参数则传入业已执行的函数内，如同函数的自身呼叫一般。所以，当执行<code><span style="font-size: small;">multiply.call(first_object, 5)</span></code>时，<code><span style="font-size: small;">multiply</span></code>被呼叫，<code><span style="font-size: small;">5</span></code>传入作为第一个参数，而<code><span style="font-size: small;">this</span></code>关键字被设置为<code><span style="font-size: small;">first_object</span></code>的引用。同样，当执行<code><span style="font-size: small;">multiply.call(second_object, 5)</span></code>时，<code><span style="font-size: small;">5</span></code>传入作为第一个参数，而<code><span style="font-size: small;">this</span></code>关键字被设置为<code><span style="font-size: small;">second_object</span></code>的引用。</p>
<p><code><span style="font-size: small;">apply</span></code>以<code><span style="font-size: small;">call</span></code>一样的方式工作，但可以让你把参数包裹进一个数组再传递给呼叫函数，在程序性生成函数呼叫时尤为有用。使用<code><span style="font-size: small;">apply</span></code>重现上一段代码，其实区别并不大：</p>
<pre><code><span style="font-size: small;">&lt;script type=&#8221;text/javascript&#8221;&gt;
 &#8230;

 multiply.apply(first_object, [5]); // 返回 42 * 5
 multiply.apply(second_object, [5]); // 返回 24 * 5
&lt;/script&gt;</span></code></pre>
<p><code><span style="font-size: small;">apply</span></code>和<code><span style="font-size: small;">call</span></code>本身都非常有用，并值得贮藏于你的工具箱内，但对于事件处理函数所改变的上下文问题，也只是送佛到西天的中途而已，剩下的还是得我们来解决。在搭建处理函数时，我们自然而然地认为，只需简单地通过使用<code><span style="font-size: small;">call</span></code>来改变<code><span style="font-size: small;">this</span></code>的含义即可：</p>
<pre><code><span style="font-size: small;">function addhandler() {
 var deep_thought = new BigComputer(42),
  the_button = document.getElementById(&#8217;thebutton&#8217;);

 the_button.onclick = deep_thought.ask_question.call(deep_thought);
}</span></code></pre>
<p>代码之所以有问题的理由很简单：<code><span style="font-size: small;">call</span></code><em>立即</em>执行了函数（译注：其实可以用一个匿名函数封装，例如<code><span style="font-size: small;">the_button.onclick = function(){deep_thought.ask_question.call(deep_thought);}</span></code>，但比起即将讨论的<code><span style="font-size: small;">bind</span></code>来，依然不够优雅）。我们给<code><span style="font-size: small;">onclcik</span></code>处理函数一个函数执行后的结果而非函数的引用。所以我们需要利用另一个JavaScript特色，以解决这个问题。</p>
<h2><code><span style="font-size: small;">.bind()</span></code>之美</h2>
<p>我并不是 <a href="http://prototypejs.org/"><span style="color: #27527d;">Prototype JavaScript framework</span></a>的忠实粉丝，但我对它的总体代码质量印象深刻。具体而言，它为<code><span style="font-size: small;">Function</span></code>对象增加一个简洁的补充，对我管理函数呼叫执行后的上下文产生了极大的正面影响：<code><span style="font-size: small;">bind</span></code>跟<code><span style="font-size: small;">call</span></code>一样执行相同的常见任务，改变函数执行的上下文。不同之处在于<code><span style="font-size: small;">bind</span></code>返回的是函数引用可以备用，而不是<code><span style="font-size: small;">call</span></code>的立即执行而产生的最终结果。</p>
<p>如果需要简化一下<code><span style="font-size: small;">bind</span></code>函数以抓住概念的重点，我们可以先把它插进前面讨论的乘积例子中去，看它究竟是如何工作的。这是一个相当优雅的解决方案：</p>
<pre><code><span style="font-size: small;">&lt;script type=&#8221;text/javascript&#8221;&gt;
 var first_object = {
  num: 42
 };
 var second_object = {
  num: 24
 };

 function multiply(mult) {
  return this.num * mult;
 }

 Function.prototype.bind = function(obj) {
  var method = this,
   temp = function() {
    return method.apply(obj, arguments);
   };

  return temp;
 }

 var first_multiply = multiply.bind(first_object);
 first_multiply(5); // 返回 42 * 5

 var second_multiply = multiply.bind(second_object);
 second_multiply(5); // 返回 24 * 5
&lt;/script&gt;</span></code></pre>
<p>首先，我们定义了<code><span style="font-size: small;">first_object</span></code>, <code><span style="font-size: small;">second_object</span></code>和<code><span style="font-size: small;">multiply</span></code>函数，一如既往。细心处理这些后，我们继续为<code><span style="font-size: small;">Function</span></code>对象的<a href="http://en.wikipedia.org/wiki/Prototype-based_programming"><code><span style="color: #27527d; font-size: small;">prototype</span></code></a>定义一个<code><span style="font-size: small;">bind</span></code>方法，这样的话，我们程序里的函数都有一个<code><span style="font-size: small;">bind</span></code>方法可用。当执行<code><span style="font-size: small;">multiply.bind(first_object)</span></code>时，JavaScript为<code><span style="font-size: small;">bind</span></code>方法创建一个运行上下文，把<code><span style="font-size: small;">this</span></code>置为<code><span style="font-size: small;">multiply</span></code>函数的引用，并把第一个参数<code><span style="font-size: small;">obj</span></code>置为<code><span style="font-size: small;">first_object</span></code>的引用。目前为止，一切皆顺。</p>
<p>这个解决方案的真正天才之处在于<code><span style="font-size: small;">method</span></code>的创建，置为<code><span style="font-size: small;">this</span></code>的引用所指（即<code><span style="font-size: small;">multiply</span></code>函数自身）。当下一行的匿名函数被创建，<code><span style="font-size: small;">method</span></code>通过它的作用域链访问，obj亦然（不要在此使用<code><span style="font-size: small;">this</span></code>, 因为新创建的函数执行后，<code><span style="font-size: small;">this</span></code>会被新的、局部的上下文覆盖）。这个<code><span style="font-size: small;">this</span></code>的别名让<code><span style="font-size: small;">apply</span></code>执行<code><span style="font-size: small;">multiply</span></code>函数成为可能，而传递<code><span style="font-size: small;">obj</span></code>则确保上下文的正确。用计算机科学的话说，<code><span style="font-size: small;">temp</span></code>是一个闭包（<a href="http://www.jibbering.com/faq/faq_notes/closures.html"><cite><span style="color: #27527d;">closure</span></cite></a>），它可以保证，需要在<code><span style="font-size: small;">first_object</span></code>的上下文中执行<code><span style="font-size: small;">multiply</span></code>，<code><span style="font-size: small;">bind</span></code>呼叫的最终返回可以用在任何的上下文中。</p>
<p>这才是前面说到的事件处理函数和<code><span style="font-size: small;">setTimeout</span></code>情形所真正需要的。以下代码完全解决了这些问题，绑定<code><span style="font-size: small;">deep_thought.ask_question</span></code>方法到<code><span style="font-size: small;">deep_thought</span></code>的上下文中，因此能在任何事件触发时都能正确运行：</p>
<pre><code><span style="font-size: small;">function addhandler() {
 var deep_thought = new BigComputer(42),
  the_button = document.getElementById(&#8217;thebutton&#8217;);

 the_button.onclick = deep_thought.ask_question.bind(deep_thought);
}</span></code></pre>
<p>漂亮。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/154/feed</wfw:commentRss>
		</item>
		<item>
		<title>FF和IE之间7个JavaScript的差异[转载]</title>
		<link>http://www.welcome58.cn/archives/153</link>
		<comments>http://www.welcome58.cn/archives/153#comments</comments>
		<pubDate>Mon, 04 May 2009 14:43:06 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Javascript/Ajax/jQuery]]></category>

		<category><![CDATA[IE FF javascript css]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=153</guid>
		<description><![CDATA[尽管 JavaScript 历史上使用冗长而令人生厌的代码块来标的特定浏览器的时期已经结束了，但是偶尔使用一些简单的代码块和对象检测来确保一些代码在用户机器上正常工作依然是必要的。
这篇文章中，我会略述一下 Internet Explorer 和 Firefox 在 JavaScript 语法上不同的 7 个方面。
1. CSS “float” 属性
获取给定对象的特定 CSS 属性的基本语法是 object.style 属性，而且有连字符的属性要用骆驼命名法来代替。例如，获取一个 ID 为 “header” 的 div 的 background-color 属性，我们要用如下语法：
document.getElementById(&#8221;header&#8221;).style.borderBottom= &#8220;1px solid #ccc&#8221;;
<span class="readmore"><a href="http://www.welcome58.cn/archives/153" title="FF和IE之间7个JavaScript的差异[转载]" target="_blank">阅读全文——共2828字</a></span>]]></description>
			<content:encoded><![CDATA[<p>尽管 JavaScript 历史上使用冗长而令人生厌的代码块来标的特定浏览器的时期已经结束了，但是偶尔使用一些简单的代码块和对象检测来确保一些代码在用户机器上正常工作依然是必要的。</p>
<p>这篇文章中，我会略述一下 Internet Explorer 和 Firefox 在 JavaScript 语法上不同的 7 个方面。</p>
<p><strong>1. CSS “float” 属性</strong></p>
<p>获取给定对象的特定 CSS 属性的基本语法是 object.style 属性，而且有连字符的属性要用骆驼命名法来代替。例如，获取一个 ID 为 “header” 的 div 的 background-color 属性，我们要用如下语法：</p>
<p><span class="code">document.getElementById(&#8221;header&#8221;).style.borderBottom= &#8220;1px solid #ccc&#8221;;</span></p>
<p>但是由于 “float” 是 JavaScript 的保留词，我们就无法使用 object.style.float 来获取 “float” 属性了。一下是我们在两种浏览器中的使用的方法：</p>
<p>IE 语法：</p>
<p><span class="code">document.getElementById(&#8221;header&#8221;).style.styleFloat = &#8220;left&#8221;;</span></p>
<p>Firefox 语法：</p>
<p><span class="code">document.getElementById(&#8221;header&#8221;).style.cssFloat = &#8220;left&#8221;;</span></p>
<p><strong>2. 元素的计算样式</strong></p>
<p>通过使用上述的 object.style.property， JavaScript 可以很容易的获取和修改对象的设定 CSS 样式。但是这一语法的局限在于，它只能取得内联在 HTML 里的样式，或者直接使用 JavaScript 设定的样式。style 对象不能获取使用外部样式表设定的样式。为了获取对象的”计算样式”，我们使用以下代码：</p>
<p>IE 语法：</p>
<p><span class="code">var myObject = document.getElementById(&#8221;header&#8221;);<br />
var myStyle = myObject.currentStyle.backgroundColor;</span></p>
<p>Firefox 语法：</p>
<p><span class="code">var myObject = document.getElementById(&#8221;header&#8221;);<br />
var myComputedStyle = document.defaultView.getComputedStyle(myObject, null);<br />
var myStyle = myComputedStyle.backgroundColor;</span></p>
<p><strong>3. 获取元素的”class”属性</strong></p>
<p>类似于”float”属性的情况，这两种浏览器使用不同的 JavaScript 方法来获取这个属性。</p>
<p>IE 语法：</p>
<p><span class="code">var myObject = document.getElementById(&#8221;header&#8221;);<br />
var myAttribute = myObject.getAttribute(&#8221;className&#8221;);</span></p>
<p>Firefox 语法：</p>
<p><span class="code">var myObject = document.getElementById(&#8221;header&#8221;);<br />
var myAttribute = myObject.getAttribute(&#8221;class&#8221;);</span></p>
<p><span class="code"><strong>4. 获取 label 标签的 “for” 属性</strong></p>
<p>和 3 一样，使用 JavaScript获取 label 的 “for” 属性也有不同语法。</p>
<p>IE 语法：</p>
<p><span class="code">var myObject = document.getElementById(&#8221;myLabel&#8221;);<br />
var myAttribute = myObject.getAttribute(&#8221;htmlFor&#8221;);</span></p>
<p>Firefox 语法：</p>
<p><span class="code">var myObject = document.getElementById(&#8221;myLabel&#8221;);<br />
var myAttribute = myObject.getAttribute(&#8221;for&#8221;);</span></p>
<p>对于 setAtrribute 方法来说也是同样的语法。</p>
<p><strong>5. 获取光标位置</strong></p>
<p>获取元素的光标位置比较少见，如果需要这么做，IE 和 Firefox 的语法也是不同的。这个示例代码是相当基础的，一般用作许多复杂事件处理的一部分，这里仅用来描述差异。需要注意的是，IE 中的结果和 Firefox 中是不同的，因此这个方法有些问题。通常，这个差异可以通过获取 “滚动位置” 来补偿 － 但那是另外一篇文章的课题了。</p>
<p>IE 语法：</p>
<p><span class="code">var myCursorPosition = [0, 0];<br />
myCursorPosition[0] = event.clientX;<br />
myCursorPosition[1] = event.clientY;</span></p>
<p>Firefox 语法：</p>
<p><span class="code">var myCursorPosition = [0, 0];<br />
myCursorPosition[0] = event.pageX;<br />
myCursorPosition[1] = event.pageY;</span></p>
<p><strong>6. 获取视窗或浏览器窗口的尺寸</strong></p>
<p>有时需要找出浏览器的有效窗口空间的尺寸，一般成为”视窗”。</p>
<p>IE 语法：</p>
<p><span class="code">var myBrowserSize = [0, 0];<br />
myBrowserSize[0] = document.documentElement.clientWidth;<br />
myBrowserSize[1] = document.documentElement.clientHeight;</span></p>
<p>Firefox 语法：</p>
<p><span class="code">var myBrowserSize = [0, 0];<br />
myBrowserSize[0] = window.innerWidth;<br />
myBrowserSize[1] = window.innerHeight;</span></p>
<p><strong>7. Alpha 透明</strong></p>
<p>嗯，这其实不是 JavaScript 的语法项目 - alpha 透明是通过 CSS 来设置的。但是当对象通过 JavaScript 设置为淡入淡出时，这就需要通过获取 CSS 的 alpha 设定来实现，一般是在循环内部。要通过以下 JavaScript 来改变 CSS 代码：</p>
<p>IE 语法：</p>
<p><span class="code">#myElement {<br />
filter: alpha(opacity=50);<br />
}</span></p>
<p>Firefox 语法：</p>
<p><span class="code">#myElement {<br />
opacity: 0.5;<br />
}</span></p>
<p>要使用 JavaScript 获取这些值，需要使用 style 对象：</p>
<p>IE 语法：</p>
<p><span class="code">var myObject = document.getElementById(&#8221;myElement&#8221;);<br />
myObject.style.filter = &#8220;alpha(opacity=80)&#8221;;</span></p>
<p>Firefox 语法：</p>
<p><span class="code">var myObject = document.getElementById(&#8221;myElement&#8221;);<br />
myObject.style.opacity = &#8220;0.5&#8243;;</span></p>
<p>当然，已经说到了，一般是在循环中间来改变 opcity/alpha，来创建动画效果，但这这是个简单的例子，只是为了明白地描述方法是如何实现地。</p>
<p>原文：<a href="http://www.impressivewebs.com/7-javascript-differences-between-firefox-ie" target="_blank">http://www.impressivewebs.com/7-javascript-differences-between-firefox-ie</a><br />
译文：<a href="http://www.qianduan.net/7-javascript-difference-between-ie-and-firefox" target="_blank">http://www.qianduan.net/7-javascript-difference-between-ie-and-firefox</a></p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/153/feed</wfw:commentRss>
		</item>
		<item>
		<title>网页中的安全字体</title>
		<link>http://www.welcome58.cn/archives/152</link>
		<comments>http://www.welcome58.cn/archives/152#comments</comments>
		<pubDate>Fri, 06 Mar 2009 01:47:06 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Html/Xhtml/Css]]></category>

		<category><![CDATA[字体 中英文]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=152</guid>
		<description><![CDATA[所谓安全字体，就是在所有的浏览器中都能正常显示的字体，也就是所有操作系统默认都安装了的字体。
共有21种安全字体：

font-family: Arial, Helvetica, sans-serif;
font-family: &#8216;Arial Black&#8217;, Gadget, sans-serif;
font-family: &#8216;Bookman Old Style&#8217;, serif;
font-family: &#8216;Comic Sans MS&#8217;, cursive;
font-family: Courier, monospace;
<span class="readmore"><a href="http://www.welcome58.cn/archives/152" title="网页中的安全字体" target="_blank">阅读全文——共3348字</a></span>]]></description>
			<content:encoded><![CDATA[<p>所谓安全字体，就是在所有的浏览器中都能正常显示的字体，也就是所有操作系统默认都安装了的字体。</p>
<p><strong>共有21种安全字体：<br />
</strong><br />
font-family: Arial, Helvetica, sans-serif;<br />
font-family: &#8216;Arial Black&#8217;, Gadget, sans-serif;<br />
font-family: &#8216;Bookman Old Style&#8217;, serif;<br />
font-family: &#8216;Comic Sans MS&#8217;, cursive;<br />
font-family: Courier, monospace;<br />
font-family: &#8216;Courier New&#8217;, Courier, monospace;<br />
font-family: Garamond, serif;<br />
font-family: Georgia, serif;<br />
font-family: Impact, Charcoal, sans-serif;<br />
font-family: &#8216;Lucida Console&#8217;, Monaco, monospace;<br />
font-family: &#8216;Lucida Sans Unicode&#8217;, &#8216;Lucida Grande&#8217;, sans-serif;<br />
font-family: &#8216;MS Sans Serif&#8217;, Geneva, sans-serif;<br />
font-family: &#8216;MS Serif&#8217;, &#8216;New York&#8217;, sans-serif;<br />
font-family: &#8216;Palatino Linotype&#8217;, &#8216;Book Antiqua&#8217;, Palatino, serif;<br />
font-family: Symbol, sans-serif;<br />
font-family: Tahoma, Geneva, sans-serif;<br />
font-family: &#8216;Times New Roman&#8217;, Times, serif;<br />
font-family: &#8216;Trebuchet MS&#8217;, Helvetica, sans-serif;<br />
font-family: Verdana, Geneva, sans-serif;<br />
font-family: Webdings, sans-serif;<br />
font-family: Wingdings, &#8216;Zapf Dingbats&#8217;, sans-serif;  </p>
<div class="runcode">
<p><textarea name="runcode" rows="10" class="runcode_text" id="runcode_OwnYdJ">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot; /&gt;
&lt;title&gt;安全字体&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
* { font-size:12px}
div { padding:5px 0; border-bottom:1px solid #ccc}
P { margin:3px 0}
.font_arial {font-family: Arial, Helvetica, sans-serif}
.font_arialblack {font-family: 'Arial Black', Gadget, sans-serif;}
.font_bookman {font-family: 'Bookman Old Style', serif;}
.font_comic {font-family: 'Comic Sans MS', cursive;}
.font_courier {font-family: Courier, monospace;}
.font_couriernew {font-family: 'Courier New', Courier, monospace;}
.font_garamond {font-family: Garamond, serif;}
.font_georgia {font-family: Georgia, serif;}
.font_impact {font-family: Impact, Charcoal, sans-serif;}
.font_lucida_c {font-family: 'Lucida Console', Monaco, monospace;}
.font_lucida_s {font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif;}
.font_mssans {font-family: 'MS Sans Serif', Geneva, sans-serif;}
.font_msserif {font-family: 'MS Serif', 'New York', sans-serif;}
.font_palatino {font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, serif;}
.font_symbol {font-family: Symbol, sans-serif;}
.font_tahoma {font-family: Tahoma, Geneva, sans-serif;}
.font_times {font-family: 'Times New Roman', Times, serif;}
.font_trebuchet {font-family: 'Trebuchet MS', Helvetica, sans-serif;}
.font_verdana {font-family: Verdana, Geneva, sans-serif;}
.font_webdings {font-family: Webdings, sans-serif;}
.font_wingdings {font-family: Wingdings, 'Zapf Dingbats', sans-serif;}
--&gt;
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;font_arial&quot;&gt;
&lt;p&gt;这是字体：font-family: Arial, Helvetica, sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_arialblack&quot;&gt;
&lt;p&gt;这是字体：font-family: 'Arial Black', Gadget, sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_bookman&quot;&gt;
&lt;p&gt;这是字体：font-family: 'Bookman Old Style', serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_comic&quot;&gt;
&lt;p&gt;这是字体：font-family: 'Comic Sans MS', cursive&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_courier&quot;&gt;
&lt;p&gt;这是字体：font-family: Courier, monospace&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_couriernew&quot;&gt;
&lt;p&gt;这是字体：font-family: 'Courier New', Courier, monospace&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_garamond&quot;&gt;
&lt;p&gt;这是字体：font-family: Garamond, serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_georgia&quot;&gt;
&lt;p&gt;这是字体：font-family: Georgia, serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_impact&quot;&gt;
&lt;p&gt;这是字体：font-family: Impact, Charcoal, sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_lucida_c&quot;&gt;
&lt;p&gt;这是字体：font-family: 'Lucida Console', Monaco, monospace&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_lucida_s&quot;&gt;
&lt;p&gt;这是字体：font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_mssans&quot;&gt;
&lt;p&gt;这是字体：font-family:  'MS Sans Serif', Geneva, sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_msserif&quot;&gt;
&lt;p&gt;这是字体：font-family: 'MS Serif', 'New York', sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_palatino&quot;&gt;
&lt;p&gt;这是字体：font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_symbol&quot;&gt;
&lt;p&gt;这是字体：font-family: Symbol, sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_tahoma&quot;&gt;
&lt;p&gt;这是字体：font-family: Tahoma, Geneva, sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_times&quot;&gt;
&lt;p&gt;这是字体：font-family: 'Times New Roman', Times, serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_trebuchet&quot;&gt;
&lt;p&gt;这是字体：font-family: 'Trebuchet MS', Helvetica, sans-seriff&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_verdana&quot;&gt;
&lt;p&gt;这是字体：font-family: Verdana, Geneva, sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_webdings&quot;&gt;
&lt;p&gt;这是字体：&lt;br /&gt;
  font-family: Webdings, sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;font_wingdings&quot;&gt;
&lt;p&gt;这是字体：&lt;br /&gt;
  font-family: Wingdings, 'Zapf Dingbats', sans-serif&lt;/p&gt;
&lt;p&gt;中文和英文混排test&lt;/p&gt;
&lt;p&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/p&gt;
&lt;p&gt;abcdefghijklmnopqrstuvwxyz&lt;/p&gt;
&lt;p&gt;0123456789&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea></p>
<p><input type="button" value="运行代码" class="runcode_button" onclick="runcode_open_new('runcode_OwnYdJ');"/> 提示：您可以先修改部分代码再运行</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/152/feed</wfw:commentRss>
		</item>
		<item>
		<title>让CSS兼容IE和Firefox的技巧集合 (上)</title>
		<link>http://www.welcome58.cn/archives/150</link>
		<comments>http://www.welcome58.cn/archives/150#comments</comments>
		<pubDate>Sun, 22 Feb 2009 07:50:26 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Html/Xhtml/Css]]></category>

		<category><![CDATA[css hack IE Firefox]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=150</guid>
		<description><![CDATA[CSS对浏览器的兼容性有时让人很头疼，或许当你了解当中的技巧跟原理，就会觉得也不是难事，从网上收集了IE7,6与Fireofx的兼容性处理方法并整理了一下。对于web2.0的过度，请尽量用xhtml格式写代码，而且DOCTYPE 影响 CSS 处理，作为W3C的标准，一定要加 DOCTYPE声明。
CSS技巧
1.div的垂直居中问题
vertical-align:middle; 将行距增加到和整个DIV一样高 line-height:200px; 然后插入文字，就垂直居中了。缺点是要控制内容不要换行
2. margin加倍的问题
设置为float的div在ie下设置的margin会加倍。这是一个ie6都存在的bug。解决方案是在这个div里面加上display:inline;
<span class="readmore"><a href="http://www.welcome58.cn/archives/150" title="让CSS兼容IE和Firefox的技巧集合 (上)" target="_blank">阅读全文——共4875字</a></span>]]></description>
			<content:encoded><![CDATA[<p>CSS对浏览器的兼容性有时让人很头疼，或许当你了解当中的技巧跟原理，就会觉得也不是难事，从网上收集了IE7,6与Fireofx的兼容性处理方法并整理了一下。对于web2.0的过度，请尽量用xhtml格式写代码，而且DOCTYPE 影响 CSS 处理，作为W3C的标准，一定要加 DOCTYPE声明。</p>
<p>CSS技巧</p>
<p><strong>1.div的垂直居中问题</strong></p>
<p>vertical-align:middle; 将行距增加到和整个DIV一样高 line-height:200px; 然后插入文字，就垂直居中了。缺点是要控制内容不要换行</p>
<p><strong>2. margin加倍的问题</strong></p>
<p>设置为float的div在ie下设置的margin会加倍。这是一个ie6都存在的bug。<a class="article" href="http://www.enet.com.cn/solution/" target="_blank">解决方案</a>是在这个div里面加上display:inline;<br />
例如：<br />
＜#div id=”imfloat”&gt;<br />
相应的css为<br />
#imfloat{<br />
float:left;<br />
margin:5px;/*IE下理解为10px*/<br />
display:inline;/*IE下再理解为5px*/}</p>
<p><strong>3.浮动ie产生的双倍距离</strong></p>
<p>#box{ float:left; width:100px; margin:0 0 0 100px; //这种情况之下IE会产生200px的距离 display:inline; //使浮动忽略}<br />
这里细说一下block与inline两个元素：block元素的特点是,总是在新行上开始,高度,宽度,行高,边距都可以控制(块元素);Inline元素的特点是,和其他元素在同一行上,不可控制(内嵌元素);<br />
#box{ display:block; //可以为内嵌元素模拟为块元素 display:inline; //实现同一行排列的效果 diplay:table;</p>
<p><strong>4 IE与宽度和高度的问题 </strong></p>
<p>IE不认得min-这个定义，但实际上它把正常的width和height当作有min的情况来使。这样问题就大了，如果只用宽度和高度，正常的浏览器里这两个值就不会变，如果只用min-width和min-height的话，IE下面根本等于没有设置宽度和高度。<br />
比如要设置背景图片，这个宽度是比较重要的。要解决这个问题，可以这样：<br />
#box{ width: 80px; height: 35px;}html&gt;body #box{ width: auto; height: auto; min-width: 80px; min-height: 35px;}</p>
<p><strong>5.页面的最小宽度</strong></p>
<p>min-width是个非常方便的CSS命令，它可以指定元素最小也不能小于某个宽度，这样就能保证排版一直正确。但IE不认得这个，而它实际上把 width当做最小宽度来使。为了让这一命令在IE上也能用，可以把一个＜div&gt; 放到 ＜body&gt; 标签下，然后为div指定一个类,然后CSS这样设计：<br />
#container{ min-width: 600px; width:expression(document.body.clientWidth ＜ 600? &#8220;600px&#8221;: &#8220;auto&#8221; );}<br />
第一个min-width是正常的；但第2行的width使用了Javascript，这只有IE才认得，这也会让你的HTML文档不太正规。它实际上通过Javascript的判断来实现最小宽度。</p>
<p><strong>6.DIV浮动IE文本产生3象素的bug</strong></p>
<p>左边对象浮动，右边采用外补丁的左边距来定位，右边对象内的文本会离左边有3px的间距.<br />
#box{ float:left; width:800px;}<br />
#left{ float:left; width:50%;}<br />
#right{ width:50%;}<br />
*html #left{ margin-right:-3px; //这句是关键}<br />
＜div id=&#8221;box&#8221;&gt;<br />
＜div id=&#8221;left&#8221;&gt;＜/div&gt;<br />
＜div id=&#8221;right&#8221;&gt;＜/div&gt;<br />
＜/div&gt;</p>
<p><strong>7.IE捉迷藏的问题 </strong></p>
<p>当div应用复杂的时候每个栏中又有一些链接，DIV等这个时候容易发生捉迷藏的问题。<br />
有些内容显示不出来，当<a class="article" href="http://www.enet.com.cn/other/mouse/" target="_blank">鼠标</a>选择这个区域是发现内容确实在页面。 解决办法：对#layout使用line-height属性 或者给#layout使用固定高和宽。页面结构尽量简单。</p>
<p><strong>8.float的div闭合;清除浮动;自适应高度;</strong>①例如：＜#div id=”floatA” &gt;＜#div id=”floatB” &gt;＜#div id=”NOTfloatC” &gt;这里的NOTfloatC并不希望继续平移，而是希望往下排。(其中floatA、floatB的属性已经设置为float:left;)<br />
这段代码在IE中毫无问题，问题出在FF。原因是NOTfloatC并非float标签，必须将float标签闭合。在 ＜#div class=”floatB”&gt; ＜#div class=”NOTfloatC”&gt;之间加上 ＜#div class=”clear”&gt;这个div一定要注意位置，而且必须与两个具有float属性的div同级，之间不能存在嵌套关系，否则会产生异常。并且将clear这种样式定义为为如下即可： .clear{ clear:both;}</p>
<p> </p>
<p>②作为外部 wrapper 的 div 不要定死高度,为了让高度能自动适应，要在wrapper里面加上overflow:hidden; 当包含float的box的时候，高度自动适应在IE下无效，这时候应该触发IE的layout私有属性(万恶的IE啊！)用zoom:1;可以做到，这样就达到了兼容。<br />
例如某一个wrapper如下定义：<br />
.colwrapper{ overflow:hidden; zoom:1; margin:5px auto;}</p>
<p>③对于排版,我们用得最多的css描述可能就是float:left.有的时候我们需要在n栏的float div后面做一个统一的背景,譬如:<br />
＜div id=”page”&gt;<br />
＜div id=”left”&gt;＜/div&gt;<br />
＜div id=”center”&gt;＜/div&gt;<br />
＜div id=”right”&gt;＜/div&gt;<br />
＜/div&gt;<br />
比如我们要将page的背景设置成蓝色,以达到所有三栏的背景颜色是蓝色的目的,但是我们会发现随着left center right的向下拉长,而page居然保存高度不变,问题来了,原因在于page不是float属性,而我们的page由于要居中,不能设置成 float,所以我们应该这样解决<br />
＜div id=”page”&gt;<br />
＜div id=”bg” style=”float:left;width:100%”&gt;<br />
＜div id=”left”&gt;＜/div&gt;<br />
＜div id=”center”&gt;＜/div&gt;<br />
＜div id=”right”&gt;＜/div&gt;<br />
＜/div&gt;<br />
＜/div&gt;<br />
再嵌入一个float left而宽度是100%的DIV解决之</p>
<p>④万能float 闭合(非常重要!)<br />
关于 clear float 的原理可参见 [How To Clear Floats Without Structural Markup],将以下代码加入Global CSS 中,给需要闭合的div加上 class=&#8221;clearfix&#8221; 即可,屡试不爽.<br />
/* Clear Fix */<br />
.clearfix:after { content:&#8221;.&#8221;; display:block; height:0; clear:both; visibility:hidden; }<br />
.clearfix { display:inline-block; }<br />
/* Hide from IE Mac */<br />
.clearfix {display:block;}<br />
/* End hide from IE Mac */<br />
/* end of clearfix */<br />
或者这样设置：.hackbox{ display:table; //将对象作为块元素级的表格显示}</p>
<p><strong>９．高度不适应 </strong></p>
<p>高度不适应是当内层对象的高度发生变化时外层高度不能自动进行调节，特别是当内层对象使用margin 或paddign 时。<br />
例：<br />
#box {background-color:#eee; }<br />
#box p {margin-top: 20px;margin-bottom: 20px; text-align:center; }<br />
＜div id=&#8221;box&#8221;&gt;<br />
＜p&gt;p对象中的内容＜/p&gt;<br />
＜/div&gt;<br />
解决方法：在P对象上下各加2个空的div对象CSS代码：.1{height:0px;overflow:hidden;}或者为DIV加上border属性。</p>
<p><strong>10 .IE6下为什么图片下有空隙产生</strong></p>
<p>解决这个BUG的方法也有很多,可以是改变html的排版,或者设置img 为display:block 或者设置vertical-align 属性为vertical-align:top 　 bottom 　middle 　text-bottom 都可以解决.</p>
<p><strong>11.如何对齐文本与文本输入框</strong></p>
<p>加上 vertical-align:middle;<br />
＜style type=&#8221;text/css&#8221;&gt;<br />
＜!&#8211;<br />
input {<br />
width:200px;<br />
height:30px;<br />
border:1px solid red;<br />
vertical-align:middle;<br />
}<br />
&#8211;&gt;<br />
＜/style&gt;</p>
<p><strong>12.web标准中定义id与class有什么区别吗</strong></p>
<p>一.web标准中是不容许重复ID的,比如 div id=&#8221;aa&#8221; 不容许重复2次,而class 定义的是类,理论上可以无限重复, 这样需要多次引用的定义便可以使用他.</p>
<p>二.属性的优先级问题<br />
ID 的优先级要高于class,看上面的例子</p>
<p>三.方便JS等客户端脚本,如果在页面中要对某个对象进行脚本操作,那么可以给他定义一个ID,否则只能利用遍历页面元素加上指定特定属性来找到它,这是相对浪费时间资源,远远不如一个ID来得简单.</p>
<p><strong>13. LI中内容超过长度后以省略号显示的方法</strong></p>
<p>此方法适用与IE与OP浏览器</p>
<p>＜style type=&#8221;text/css&#8221;&gt;<br />
＜!&#8211;<br />
li {<br />
width:200px;<br />
white-space:nowrap;<br />
text-overflow:ellipsis;<br />
-o-text-overflow:ellipsis;<br />
overflow: hidden;<br />
}</p>
<p>&#8211;&gt;<br />
＜/style&gt;</p>
<p><strong>14.为什么web标准中IE无法设置滚动条颜色了</strong></p>
<p>解决办法是将body换成html<br />
＜!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Strict//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#8221;&gt;<br />
＜meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=gb2312&#8243; /&gt;<br />
＜style type=&#8221;text/css&#8221;&gt;<br />
＜!&#8211;<br />
html {<br />
scrollbar-face-color:#f6f6f6;<br />
scrollbar-highlight-color:#fff;<br />
scrollbar-shadow-color:#eeeeee;<br />
scrollbar-3dlight-color:#eeeeee;<br />
scrollbar-arrow-color:#000;<br />
scrollbar-track-color:#fff;<br />
scrollbar-darkshadow-color:#fff;<br />
}<br />
&#8211;&gt;<br />
＜/style&gt;</p>
<p><strong>15.为什么无法定义1px左右高度的容器</strong></p>
<p>IE6下这个问题是因为默认的行高造成的,解决的方法也有很多,例如:overflow:hidden 　 zoom:0.08 　 line-height:1px</p>
<p>16.怎么样才能让层显示在FLASH之上呢</p>
<p>解决的办法是给FLASH设置透明<br />
＜param name=&#8221;wmode&#8221; value=&#8221;transparent&#8221; /&gt;</p>
<p><strong>17.怎样使一个层垂直居中于浏览器中</strong></p>
<p>这里我们使用百分比绝对定位,与外补丁负值的方法,负值的大小为其自身宽度高度除以二<br />
＜style type=&#8221;text/css&#8221;&gt;<br />
＜!&#8211;<br />
div {<br />
position:absolute;<br />
top:50%;<br />
lef:50%;<br />
margin:-100px 0 0 -100px;<br />
width:200px;<br />
height:200px;<br />
border:1px solid red;<br />
}<br />
&#8211;&gt;<br />
＜/style&gt;</p>
<p> </p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/150/feed</wfw:commentRss>
		</item>
		<item>
		<title>让CSS兼容IE和Firefox的技巧集合 (下)</title>
		<link>http://www.welcome58.cn/archives/151</link>
		<comments>http://www.welcome58.cn/archives/151#comments</comments>
		<pubDate>Sun, 22 Feb 2009 07:50:17 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Html/Xhtml/Css]]></category>

		<category><![CDATA[css hack IE Firefox 兼容]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=151</guid>
		<description><![CDATA[FF与IE
1. Div居中问题
div设置 margin-left, margin-right 为 auto 时已经居中，IE 不行，IE需要设定body居中，首先在父级元素定义text-algin: center;这个的意思就是在父级元素内的内容居中。
2.链接(a标签)的边框与背景
a链接加边框和背景色，需设置 display: block, 同时设置 float: left 保证不换行。参照 menubar, 给 a 和 menubar 设置高度是为了避免底边显示错位, 若不设 height, 可以在 menubar 中插入一个空格。
3.超链接访问过后hover样式就不出现的问题
被点击访问过的超链接样式不在具有hover和active了,很多人应该都遇到过这个问题,解决方法是改变CSS属性的排列顺序: L-V-H-A
<span class="readmore"><a href="http://www.welcome58.cn/archives/151" title="让CSS兼容IE和Firefox的技巧集合 (下)" target="_blank">阅读全文——共4442字</a></span>]]></description>
			<content:encoded><![CDATA[<p><strong>FF与IE</strong></p>
<p>1. Div居中问题</p>
<p>div设置 margin-left, margin-right 为 auto 时已经居中，IE 不行，IE需要设定body居中，首先在父级元素定义text-algin: center;这个的意思就是在父级元素内的内容居中。</p>
<p><strong>2.链接(a标签)的边框与背景</strong></p>
<p>a链接加边框和背景色，需设置 display: block, 同时设置 float: left 保证不换行。参照 menubar, 给 a 和 menubar 设置高度是为了避免底边显示错位, 若不设 height, 可以在 menubar 中插入一个空格。</p>
<p><strong>3.超链接访问过后hover样式就不出现的问题</strong></p>
<p>被点击访问过的超链接样式不在具有hover和active了,很多人应该都遇到过这个问题,解决方法是改变CSS属性的排列顺序: L-V-H-A<br />
Code:<br />
＜style type=&#8221;text/css&#8221;&gt;<br />
＜!&#8211;<br />
a:link {}<br />
a:visited {}<br />
a:hover {}<br />
a:active {}<br />
&#8211;&gt;<br />
＜/style&gt;</p>
<p><strong>4. 游标手指cursor </strong></p>
<p>cursor: pointer 可以同时在 IE FF 中显示游标手指状， hand 仅 IE 可以</p>
<p><strong>5.UL的padding与margin </strong></p>
<p>ul标签在FF中默认是有padding值的,而在IE中只有margin默认有值,所以先定义 ul{margin:0;padding:0;}就能解决大部分问题</p>
<p><strong>6. FORM标签</strong></p>
<p>这个标签在IE中,将会自动margin一些边距,而在FF中margin则是0,因此,如果想显示一致,所以最好在css中指定margin和 padding,针对上面两个问题,我的css中一般首先都使用这样的样式ul,form{margin:0;padding:0;}给定义死了,所以后面就不会为这个头疼了.</p>
<p><strong>7. BOX模型解释不一致问题</strong></p>
<p>在FF和IE中的BOX模型解释不一致导致相差2px解决方法：div{margin:30px!important;margin:28px;} 注意这两个margin的顺序一定不能写反， important这个属性IE不能识别，但别的浏览器可以识别。所以在IE下其实解释成这样： div{maring:30px;margin:28px}重复定义的话按照最后一个来执行，所以不可以只写margin:xx px!important;<br />
#box{ width:600px; //for ie6.0- w\idth:500px; //for ff+ie6.0}<br />
#box{ width:600px!important //for ff width:600px; //for ff+ie6.0 width /**/:500px; //for ie6.0-}</p>
<p><strong>8.属性选择器(这个不能算是兼容,是隐藏css的一个bug) </strong></p>
<p>p[id]{}div[id]{}<br />
这个对于IE6.0和IE6.0以下的版本都隐藏,FF和OPera作用.属性选择器和子选择器还是有区别的,子选择器的范围从形式来说缩小了,属性选择器的范围比较大,如p[id]中,所有p标签中有id的都是同样式的.</p>
<p><strong>9.最狠的手段 - !important; </strong></p>
<p>如果实在没有办法解决一些细节问题,可以用这个方法.FF对于”!important”会自动优先解析,然而IE则会忽略.如下<br />
.tabd1{<br />
background:url(/res/images/up/tab1.gif) no-repeat 0px 0px !important; /*Style for FF*/<br />
background:url(/res/images/up/tab1.gif) no-repeat 1px 0px; /* Style for IE */}<br />
值得注意的是，一定要将xxxx !important 这句放置在另一句之上，上面已经提过</p>
<p><strong>10.IE,FF的默认值问题</strong>或许你一直在抱怨为什么要专门为IE和FF写不同的CSS，为什么IE这样让人头疼，然后一边写css，一边咒骂那个可恶的M$ IE.其实对于css的标准支持方面，IE并没有我们想象的那么可恶，关键在于IE和FF的默认值不一样而已，掌握了这个技巧，你会发现写出兼容FF和 IE的css并不是那么困难，或许对于简单的css，你完全可以不用”!important”这个东西了。<br />
我们都知道，浏览器在显示网页的时候，都会根据网页的css样式表来决定如何显示，但是我们在样式表中未必会将所有的元素都进行了具体的描述，当然也没有必要那么做，所以对于那些没有描述的属性，浏览器将采用内置默认的方式来进行显示，譬如文字，如果你没有在css中指定颜色，那么浏览器将采用黑色或者系统颜色来显示，div或者其他元素的背景，如果在css中没有被指定，浏览器则将其设置为白色或者透明，等等其他未定义的样式均如此。所以有很多东西出现 FF和IE显示不一样的根本原因在于它们的默认显示不一样，而这个默认样式该如何显示我知道在w3中有没有对应的标准来进行规定，因此对于这点也就别去怪罪IE了。</p>
<p> </p>
<p><strong>11.为什么FF下文本无法撑开容器的高度</strong></p>
<p>标准浏览器中固定高度值的容器是不会象IE6里那样被撑开的,那我又想固定高度,又想能被撑开需要怎样设置呢？办法就是去掉height设置min- height:200px; 这里为了照顾不认识min-height的IE6 可以这样定义:</p>
<p>{<br />
height:auto!important;<br />
height:200px;<br />
min-height:200px;<br />
}</p>
<p><strong>12.FireFox下如何使连续长字段自动换行</strong></p>
<p>众所周知IE中直接使用 word-wrap:break-word 就可以了, FF中我们使用JS插入<br />
的方法来解决</p>
<p>＜style type=&#8221;text/css&#8221;&gt;<br />
＜!&#8211;<br />
div {<br />
width:300px;<br />
word-wrap:break-word;<br />
border:1px solid red;<br />
}<br />
&#8211;&gt;<br />
＜/style&gt;</p>
<p>＜div id=&#8221;ff&#8221;&gt;aaaaaaaaaaaaaaaaaaaaaaaaaaaa＜/div&gt;</p>
<p>＜scrīpt type=&#8221;text/javascrīpt&#8221;&gt;<br />
/* ＜![CDATA[ */<br />
function toBreakWord(el, intLen){<br />
var ōbj=document.getElementById(el);<br />
var strContent=obj.innerHTML;<br />
var strTemp=&#8221;";<br />
while(strContent.length&gt;intLen){<br />
strTemp+=strContent.substr(0,intLen)+&#8221;<br />
&#8220;;<br />
strContent=strContent.substr(intLen,strContent.length);<br />
}<br />
strTemp+=&#8221;<br />
&#8220;+strContent;<br />
obj.innerHTML=strTemp;<br />
}<br />
if(document.getElementById &amp;&amp; !document.all) toBreakWord(&#8221;ff&#8221;, 37);<br />
/* ]]&gt; */<br />
＜/scrīpt&gt;</p>
<p><strong>13.为什么IE6下容器的宽度和FF解释不同呢</strong>＜?xml version=&#8221;1.0&#8243; encoding=&#8221;gb2312&#8243;?&gt;<br />
＜!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Strict//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#8221;&gt;<br />
＜meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=gb2312&#8243; /&gt;<br />
＜style type=&#8221;text/css&#8221;&gt;<br />
＜!&#8211;<br />
div {<br />
cursor:pointer;<br />
width:200px;<br />
height:200px;<br />
border:10px solid red<br />
}<br />
&#8211;&gt;<br />
＜/style&gt;<br />
＜div ōnclick=&#8221;alert(this.offsetWidth)&#8221;&gt;让FireFox与IE兼容＜/div&gt;</p>
<p> </p>
<p>问题的差别在于容器的整体宽度有没有将边框（border）的宽度算在其内,这里IE6解释为200PX ,而FF则解释为220PX,那究竟是怎么导致的问题呢？大家把容器顶部的xml去掉就会发现原来问题出在这,顶部的申明触发了IE的qurks mode,关于qurks mode、standards mode的相关知识,请参考:http://www.microsoft.com/china/msdn/library/webservices /asp.net/<br />
ASPNETusStan.mspx?mfr=true</p>
<p>IE6,IE7,FF</p>
<p>IE7.0出来了，对CSS的支持又有新问题。浏览器多了，网Bpx; /*For IE7 &amp; IE6*/<br />
_height:20px; /*For IE6*/</p>
<p>注意顺序。</p>
<p>这样也属于CSS HACK，不过没有上面这样简洁。<br />
#example { color: #333; } /* Moz */<br />
* html #example { color: #666; } /* IE6 */<br />
*+html #example { color: #999; } /* IE7 */</p>
<p>第二种，是使用IE专用的条件注释</p>
<p>＜!&#8211;其他浏览器 &#8211;&gt;<br />
＜link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;css.css&#8221; /&gt;</p>
<p>＜!&#8211;[if IE 7]&gt;<br />
＜!&#8211; 适合于IE7 &#8211;&gt;<br />
＜link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie7.css&#8221; /&gt;<br />
＜![endif]&#8211;&gt;</p>
<p>＜!&#8211;[if lte IE 6]&gt;<br />
＜!&#8211; 适合于IE6及一下 &#8211;&gt;<br />
＜link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie.css&#8221; /&gt;<br />
＜![endif]&#8211;&gt;</p>
<p><strong>第三种，css filter的办法，以下为经典从国外网站翻译过来的。. </strong></p>
<p>新建一个css样式如下：<br />
#item {<br />
width: 200px;<br />
height: 200px;<br />
background: red;<br />
}</p>
<p>新建一个div,并使用前面定义的css的样式：<br />
＜div id=&#8221;item&#8221;&gt;some text here＜/div&gt;</p>
<p>在body表现这里加入lang属性,中文为zh：<br />
＜body lang=&#8221;en&#8221;&gt;</p>
<p>现在对div元素再定义一个样式：<br />
*:lang(en) #item{<br />
background:green !important;<br />
}</p>
<p>这样做是为了用!important覆盖原来的css样式,由于:lang选择器ie7.0并不支持,所以对这句话不会有任何作用,于是也达到了 ie6.0下同样的效果,但是很不幸地的是,safari同样不支持此属性,所以需要加入以下css样式：<br />
#item:empty {<br />
background: green !important<br />
}<br />
:empty选择器为css3的规范,尽管safari并不支持此规范,但是还是会选择此元素,不管是否此元素存在,现在绿色会现在在除ie各版本以外的浏览器上。</p>
<p>对IE6和FF的兼容可以考虑以前的!important 个人比较喜欢用第一种，简洁，兼容性比较好。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/151/feed</wfw:commentRss>
		</item>
		<item>
		<title>IE6实现min-width</title>
		<link>http://www.welcome58.cn/archives/149</link>
		<comments>http://www.welcome58.cn/archives/149#comments</comments>
		<pubDate>Thu, 19 Feb 2009 06:32:35 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Html/Xhtml/Css]]></category>

		<category><![CDATA[他山之石]]></category>

		<category><![CDATA[IE6 min-width]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=149</guid>
		<description><![CDATA[首先我们知道这个效果应该是一个老话题了。
今天整理文件的时候，发现自己以前的一些布局的解决方法躺在文件夹里很长时间了，翻翻老底吧
需要说明的是有幸也见到过CSSPLAY的老工程师站长对这个效果的实现，而且肯定是很早就给出来了。
闲话少说，上源码：
触发并利用IE6-layout的怪异特性，css实现：
 
&#60;div class=&#34;ie6-out&#34;&#62;
&#60;div class=&#34;ie6-in&#34;&#62;
<span class="readmore"><a href="http://www.welcome58.cn/archives/149" title="IE6实现min-width" target="_blank">阅读全文——共584字</a></span>]]></description>
			<content:encoded><![CDATA[<p>首先我们知道这个效果应该是一个老话题了。<br />
今天整理文件的时候，发现自己以前的一些布局的解决方法躺在文件夹里很长时间了，翻翻老底吧<br />
需要说明的是有幸也见到过CSSPLAY的老工程师站长对这个效果的实现，而且肯定是很早就给出来了。</p>
<p>闲话少说，上源码：</p>
<p>触发并利用IE6-layout的怪异特性，css实现：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"> </li>
<li>&lt;div class=&quot;ie6-out&quot;&gt;</li>
<li>&lt;div class=&quot;ie6-in&quot;&gt;</li>
<li>&lt;div id=&quot;min-width&quot; style=&quot;width: 900px;&quot;&gt;ie6-下，容器实现模拟min-width效果。请任意改变浏览器窗口大小，再点击按钮“查看宽度”。&lt;/div&gt;</li>
<li>&lt;/div&gt;</li>
<li>&lt;/div&gt;</li></ol></div>
<p>css实现演示：<br />
运行代码框</p>
<p> </p>
<p> 
<div class="runcode">
<p><textarea name="runcode" rows="10" class="runcode_text" id="runcode_ARIvIm">
&lt;div class=&quot;ie6-out&quot;&gt;
&lt;div class=&quot;ie6-in&quot;&gt;
&lt;div id=&quot;min-width&quot; style=&quot;width: 900px;&quot;&gt;ie6-下，容器实现模拟min-width效果。请任意改变浏览器窗口大小，再点击按钮“查看宽度”。&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;input onclick=&quot;alert('容器宽度='+document.getElementById('min-width').clientWidth+'px'+'\n\n'+'视口宽度='+(document.documentElement.clientWidth||document.body.clientWidth)+'px');&quot; maxlength=&quot;2147483647&quot; size=&quot;20&quot; type=&quot;button&quot; value=&quot;查看宽度&quot; /&gt;
</textarea></p>
<p><input type="button" value="运行代码" class="runcode_button" onclick="runcode_open_new('runcode_ARIvIm');"/> 提示：您可以先修改部分代码再运行</p>
</div>
<p><span>扩展演示：</span></p>
<div class="runcode">
<p><textarea name="runcode" rows="10" class="runcode_text" id="runcode_OwT_s6">
 
 
&lt;div class=&quot;ie6-out&quot;&gt;
&lt;div class=&quot;ie6-in&quot;&gt;aa&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;ie6-out&quot;&gt;
&lt;div class=&quot;ie6-in&quot;&gt;aa
&lt;div id=&quot;min-width&quot; style=&quot;width: 900px;&quot;&gt;ie6-下，容器实现模拟min-width效果。请任意改变浏览器窗口大小，再点击按钮“查看宽度”。&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;input onclick=&quot;alert('容器宽度='+document.getElementById('min-width').clientWidth+'px'+'\n\n'+'视口宽度='+(document.documentElement.clientWidth||document.body.clientWidth)+'px');&quot; maxlength=&quot;2147483647&quot; size=&quot;20&quot; type=&quot;button&quot; value=&quot;查看宽度&quot; /&gt;
</textarea></p>
<p><input type="button" value="运行代码" class="runcode_button" onclick="runcode_open_new('runcode_OwT_s6');"/> 提示：您可以先修改部分代码再运行</p>
</div>
<p>CSS Expression<br />
——相信许多人在用这个方法实现容器最小宽度时都时常会被莫名其妙的死机所困扰，最后往往无果而终。</p>
<p>这里特别需要指出的是两点：<br />
1. IE6-的标准模式下和quirk模式下代表视口的元素是不一样的，前者为，后者则为；<br />
2. IE6-在以上两种不同的模式下，其对包含内容溢出时的不同表现形式，从而导致了赋值判断上的死循环。解释起来有些啰嗦，自己实践一下吧。</p>
<p>CSS Expression实现最小宽度源码：</p>
<p> </p>
<div id="min-width" style="width: 900px;">ie6-下，容器实现模拟min-width效果。请任意改变浏览器窗口大小，再点击按钮“查看宽度”。</div>
<p>演示：<br />
运行代码框</p>
<div class="runcode">
<p><textarea name="runcode" rows="10" class="runcode_text" id="runcode_UT5YLj">
&lt;!--CTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--&gt;
 
 
&lt;div id=&quot;min-width&quot; style=&quot;width: 900px;&quot;&gt;ie6-下，容器实现模拟min-width效果。请任意改变浏览器窗口大小，再点击按钮“查看宽度”。&lt;/div&gt;
&lt;input onclick=&quot;alert('容器宽度='+document.getElementById('min-width').clientWidth+'px'+'\n\n'+'视口宽度='+(document.documentElement.clientWidth||document.body.clientWidth)+'px');&quot; maxlength=&quot;2147483647&quot; size=&quot;20&quot; type=&quot;button&quot; value=&quot;查看宽度&quot; /&gt;
</textarea></p>
<p><input type="button" value="运行代码" class="runcode_button" onclick="runcode_open_new('runcode_UT5YLj');"/> 提示：您可以先修改部分代码再运行</p>
</div>
<p>以上两种解决方法在IE6-的标准模式下和quirk模式下都可实现，IE Expression在这个应用中也未发现CPU效率问题。</p>
<p>本文链接：http://www.blueidea.com/tech/web/2008/5869.asp　</p>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/149/feed</wfw:commentRss>
		</item>
		<item>
		<title>CSS hacks</title>
		<link>http://www.welcome58.cn/archives/148</link>
		<comments>http://www.welcome58.cn/archives/148#comments</comments>
		<pubDate>Wed, 29 Oct 2008 02:10:28 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Html/Xhtml/Css]]></category>

		<category><![CDATA[他山之石]]></category>

		<category><![CDATA[CSS hacks]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=148</guid>
		<description><![CDATA[IE6以下
*html{}
IE 7 以下
*:first-child+html {} * html {}
只对IE 7
*:first-child+html {}
只对IE 7 和现代浏览器
html&#62;body {}
<span class="readmore"><a href="http://www.welcome58.cn/archives/148" title="CSS hacks" target="_blank">阅读全文——共2170字</a></span>]]></description>
			<content:encoded><![CDATA[<p>IE6以下</p>
<p>*html{}</p>
<p>IE 7 以下</p>
<p>*:first-child+html {} * html {}</p>
<p>只对IE 7</p>
<p>*:first-child+html {}</p>
<p>只对IE 7 和现代浏览器</p>
<p>html&gt;body {}</p>
<p>只对现代浏览器(非IE 7)</p>
<p>html&gt;/**/body {}</p>
<p>最新的Opera 9以下版本</p>
<p>html:first-child {}</p>
<p>Safari</p>
<p>html[xmlns*=”&#8221;] body:last-child {}</p>
<p>要使用这些选择器，请在样式前写下这些代码。例如：</p>
<p>#content-box {<br />
width: 300px;</p>
<p>height: 150px;</p>
<p>}</p>
<p>* html #content-box {</p>
<p>width: 250px;</p>
<p>}</p>
<p>/* 重写上面的代码并且把宽度改为250PX</p>
<p>在IE6以下版本中适用。 */</p>
<p>3、在IE6中使用透明PNG图片</p>
<p>IE6的一个很难处理的BUG就是它不支持透明PNG图片。</p>
<p>你可能需要用一个重写的CSS的滤镜来解决这个问题：</p>
<p>*html #image-style {</p>
<p>background-image: none;</p>
<p>filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=”/”fil”</p>
<p>ename.png”, sizingMethod=”scale”);</p>
<p>}</p>
<p>4、去掉连接虚线框</p>
<p>当你点击链接时，Firefox会在链接周围产生一个虚线外框。</p>
<p>这个很好解决，只需在a标签中添加outline:none就可以了。</p>
<p>a{</p>
<p>outline:none;</p>
<p>}<br />
5、对inline元素应用宽度。</p>
<p>如果你对一个inline元素使用宽度，它将只在IE6下起作用。</p>
<p>所以的HTML标签要么是Block的要么就是inline的。inline属性的标签有&lt;span&gt;&lt;a&gt;&lt; strong&gt;和&lt;em&gt;Block标签包括&lt;div&gt;&lt;p&gt;&lt;h1&gt;&lt;form&gt; 和&lt;li&gt;</p>
<p>你不能控制inilne标签的宽带，不过有一个方法是把标签属性从inline改为Block。</p>
<p>span{</p>
<p>width:150px;</p>
<p>display:block;</p>
<p>}</p>
<p>应用display:block能够把span标签变成block标签，从而控制它的宽度。</p>
<p>6、使一个固定宽度的网站居中。</p>
<p>为了让你的网站在浏览器中居中，可以为最外层Div添加position:relative属性，然后将margin设为auto。</p>
<p>#wrapper {</p>
<p>margin: auto;</p>
<p>position: relative;</p>
<p>}</p>
<p>7、图片替换技术</p>
<p>对于头部来说，永远是最好用文字而不是图片。在你必须要用图片的某个特殊地方最好使用隐藏文字的层的背景图片。这对于屏幕阅读和SEO非常有用，尽管依然使用很普通的文字，这可以联想到所有的优点。</p>
<p>HTML：</p>
<p>&lt;h1&gt;&lt;span&gt;Main heading one&lt;/span&gt;&lt;/h1&gt;</p>
<p>CSS:</p>
<p>h1 {</p>
<p>background: url(heading-image.gif) no-repeat;</p>
<p>}</p>
<p>h1 span {</p>
<p>position:absolute;</p>
<p>text-indent: -5000px;</p>
<p>}</p>
<p>正如你所见，我们对H1标签使用普通的HTML代码，用CSS来将图片替代文字。Text-indent把文字放到左边5000像素处，从而用户看不到它们。</p>
<p>8、最小宽度</p>
<p>IE的另外一个Bug就是它不支持min-width属性。min-width确实非常有用，特别是对于100%宽度的可变模板来说，因为他告诉浏览器停止收缩。</p>
<p>对于除IE6以外的所有浏览器来说你只需min-width:xpx;例如：</p>
<p>.container {</p>
<p>min-width:300px;</p>
<p>}</p>
<p>要让这些在IE6下起作用的话你要添加额外的努力！你需要创建两个DIV，一个包含着另一个。</p>
<p>&lt;div class=”container”&gt;</p>
<p>&lt;div class=”holder”&gt;Content&lt;/div&gt;</p>
<p>&lt;/div&gt;</p>
<p>然后你需要设置外面层的min-width：</p>
<p>.container {</p>
<p>min-width:300px;</p>
<p>}</p>
<p>现在又要IE hack起作用了，你需要写下以下代码：</p>
<p>* html .container {</p>
<p>border-right: 300px solid #FFF;</p>
<p>}</p>
<p>* html .holder {</p>
<p>display: inline-block;</p>
<p>position: relative;</p>
<p>margin-right: -300px;</p>
<p>}</p>
<p>当浏览器窗口调整外层宽度来适应直到它缩小到border的宽度时，这个时候它就不能够在缩小了。而holder层也会停止收缩。外层的边框宽度变成了内层的最小宽度。</p>
<p>9、隐藏水平滚动</p>
<p>要去除水平滚动条，可以在body中插入overflow-x:hidden属性。</p>
<p>body {</p>
<p>overflow-x: hidden;</p>
<p>}</p>
<p>这在你决意要用一个比浏览器款的图片或Flash时很有用。</p>
<p>如果需要批量解决整站点的超链接虚线框，一个一个加这样的代码，不是要晕了。<br />
可以使用两种方法解决：<br />
第一，使用DW中的插件：scrubber.mxp，代点是可以对于整页内的超链接进行处理，但无法对整站点消除虚线框，有局限性。<br />
第二，使用样式表，这样，就可以对整站进行处理了。<br />
样式代码：<br />
a {blr:expression(this.onFocus=this.blur())}<br />
如果是图片区域，可以加：<br />
area {blr:expression(this.onFocus=this.blur())}</p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/148/feed</wfw:commentRss>
		</item>
		<item>
		<title>屏蔽选择的样式定义：-moz-user-select属性</title>
		<link>http://www.welcome58.cn/archives/147</link>
		<comments>http://www.welcome58.cn/archives/147#comments</comments>
		<pubDate>Mon, 20 Oct 2008 07:31:01 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Html/Xhtml/Css]]></category>

		<category><![CDATA[屏蔽选择 -moz-user-select]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=147</guid>
		<description><![CDATA[屏蔽选择的样式定义：-moz-user-select属性（只支持ff）。 
属性有三个属性值： 
1、 none：用none,子元素所有的文字都不能选择，包括input输入框中的文字也不能选择。
2、 -moz-all：子元素所有的文字都可以被选择，但是input输入框中的文字不可以被选择。
3、 -moz-none：子元素所有的文字都不能选择，但是input输入框中的文字除外。
  IE浏览器下是通过 onselectstart=&#8221;javascript:return false;&#8221;事件来实现该功能。


<span class="readmore"><a href="http://www.welcome58.cn/archives/147" title="屏蔽选择的样式定义：-moz-user-select属性" target="_blank">阅读全文——共246字</a></span>]]></description>
			<content:encoded><![CDATA[<div></div>
<p><span class="Apple-style-span" style="orphans: 2; word-spacing: 0px; text-transform: none; color: #796e5e; widows: 2; text-indent: 0px; font-family: Arial; white-space: normal; letter-spacing: normal; border-collapse: separate; text-align: left; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0;"></p>
<p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 10px; COLOR: #796e5e; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">屏蔽选择的样式定义：</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">-moz-user-select</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">属性（只支持</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">ff</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">）。</span> </p>
<p><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">属性有三个属性值：</span> </p>
<p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 10px; COLOR: #796e5e; TEXT-INDENT: -18pt; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">1、<span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span class="Apple-converted-space"> </span></span></span></span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">none</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">：</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">用</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">none,</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">子元素所有的文字都不能选择，包括</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">input</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">输入框中的文字也不能选择。</span></p>
<p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 10px; COLOR: #796e5e; TEXT-INDENT: -18pt; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">2、<span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span class="Apple-converted-space"> </span></span></span></span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">-moz-all</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">：子元素所有的文字都可以被选择，但是</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">input</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">输入框中的文字不可以被选择。</span></p>
<p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 10px; COLOR: #796e5e; TEXT-INDENT: -18pt; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">3、<span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span class="Apple-converted-space"> </span></span></span></span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">-moz-none</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">：子元素所有的文字都不能选择，但是</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">input</span><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px">输入框中的文字除外。</span></p>
<p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 10px; COLOR: #796e5e; TEXT-INDENT: -18pt; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; LINE-HEIGHT: 160%; PADDING-TOP: 0px"><span class="Apple-style-span" style="orphans: 2; word-spacing: 0px; text-transform: none; color: #796e5e; widows: 2; text-indent: 0px; font-family: Arial; white-space: normal; letter-spacing: normal; border-collapse: separate; text-align: left; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0;"><span style="margin: 0px; line-height: 160%; padding: 0px;">  IE</span><span style="margin: 0px; line-height: 160%; padding: 0px;">浏览器下是通过</span><span class="Apple-converted-space"> </span><span style="margin: 0px; line-height: 160%; padding: 0px;">onselectstart=&#8221;javascript:return false;&#8221;</span><span style="margin: 0px; line-height: 160%; padding: 0px;">事件来实现该功能。</span></span></span></p>
<div class="runcode">
<p><textarea name="runcode" rows="10" class="runcode_text" id="runcode_IuEDct">
&lt;!--CTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dt--&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
&amp;nbsp;   //&lt;![CDATA[&lt;/div&gt;
&lt;div mce_tmp=&quot;1&quot;&gt;    //]]&gt;
&amp;nbsp;
// --&gt;&lt;/script&gt;
&lt;/span&gt;
&lt;h1&gt;-moz-user-select&lt;/h1&gt;
&lt;h4&gt;Mozilla Firefox下，拖拽（选择）无效&lt;/h4&gt;
屏蔽选择的样式定义：-moz-user-select属性（只支持ff）。
属性有三个属性值：
1、 none：用none,子元素所有的文字都不能选择，包括input输入框中的文字也不能选择。
2、 -moz-all：子元素所有的文字都可以被选择，但是input输入框中的文字不可以被选择。
3、 -moz-none：子元素所有的文字都不能选择，但是input输入框中的文字除外。
</textarea></p>
<p><input type="button" value="运行代码" class="runcode_button" onclick="runcode_open_new('runcode_IuEDct');"/> 提示：您可以先修改部分代码再运行</p>
</div>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/147/feed</wfw:commentRss>
		</item>
		<item>
		<title>CHROME</title>
		<link>http://www.welcome58.cn/archives/146</link>
		<comments>http://www.welcome58.cn/archives/146#comments</comments>
		<pubDate>Sun, 28 Sep 2008 01:37:41 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Javascript/Ajax/jQuery]]></category>

		<category><![CDATA[CHROME]]></category>

		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=146</guid>
		<description><![CDATA[前段时间诞生的Google浏览器CHROME，引起很多人关注，应该大部分都是“业内人士”，我也下载了一个试了试，以下是我的感想：
1.界面简洁，功能简单，打破了以往浏览器的功能布局;
2.Javascript的运行速度确实可观;
3.目前版本容易崩溃;
4.全面支持目前CSS选择符，参见http://www.evotech.net/blog/2008/09/google-chrome-browser-css-selector-support/
]]></description>
			<content:encoded><![CDATA[<p>前段时间诞生的Google浏览器CHROME，引起很多人关注，应该大部分都是“业内人士”，我也下载了一个试了试，以下是我的感想：<br />
1.界面简洁，功能简单，打破了以往浏览器的功能布局;<br />
2.Javascript的运行速度确实可观;<br />
3.目前版本容易崩溃;<br />
4.全面支持目前CSS选择符，参见<a href="http://www.evotech.net/blog/2008/09/google-chrome-browser-css-selector-support/">http://www.evotech.net/blog/2008/09/google-chrome-browser-css-selector-support/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/146/feed</wfw:commentRss>
		</item>
		<item>
		<title>跨浏览器实现float:center</title>
		<link>http://www.welcome58.cn/archives/145</link>
		<comments>http://www.welcome58.cn/archives/145#comments</comments>
		<pubDate>Wed, 27 Aug 2008 13:33:52 +0000</pubDate>
		<dc:creator>缘由心生</dc:creator>
		
		<category><![CDATA[Html/Xhtml/Css]]></category>

		<category><![CDATA[他山之石]]></category>

		<category><![CDATA[center]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[float]]></category>

		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.welcome58.cn/?p=145</guid>
		<description><![CDATA[原文：
http://www.macji.com/blog/article/to-achieve-cross-browser-css-float-center/to-achieve-cross-browser-css-float-center/
一直想实现一种类似float:left/right的居中效果，但想了好久，也问了好多大侠，一直没解决，今天在蓝色看见了，大喜！
&#60;div id=&#34;macji&#34;&#62;
&#160;&#160; &#160;&#60;ul class=&#34;macji-skin&#34;&#62;
&#160;&#160; &#160; &#160; &#160;&#60;li&#62;列表一&#60;/li&#62;
<span class="readmore"><a href="http://www.welcome58.cn/archives/145" title="跨浏览器实现float:center" target="_blank">阅读全文——共1165字</a></span>]]></description>
			<content:encoded><![CDATA[<p>原文：<br />
<a href="http://www.macji.com/blog/article/to-achieve-cross-browser-css-float-center/to-achieve-cross-browser-css-float-center/" target="_blank">http://www.macji.com/blog/article/to-achieve-cross-browser-css-float-center/to-achieve-cross-browser-css-float-center/</a></p>
<p>一直想实现一种类似float:left/right的居中效果，但想了好久，也问了好多大侠，一直没解决，今天在蓝色看见了，大喜！</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">&lt;div id=&quot;macji&quot;&gt;</li>
<li>&nbsp;&nbsp; &nbsp;&lt;ul class=&quot;macji-skin&quot;&gt;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;li&gt;列表一&lt;/li&gt;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;li&gt;列表二&lt;/li&gt;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;li&gt;列表三&lt;/li&gt;</li>
<li>&nbsp;&nbsp; &nbsp;&lt;/ul&gt;</li>
<li>&lt;/div&gt;</li></ol></div>
<p>我们希望实现li是浮动的，并且居中的（li个数不固定，ul宽度未知）。可以设置ul的text-align:center,再设置li的display，可以实现居中，但这样不是我们的初衷，我们需要实现float:center。</p>
<p>这里我们得先重温一下position:relative，它将依据left，right，top，bottom等属性在正常文档流中偏移位置。那我们可以让ul为position:relative;left:50%，然后再让li像左浮动，在让它position:relative;right:50%（或者left:-50%），那么li就像向中间浮动一样居中了。废话不多说，先试试。</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">#macji{</li>
<li>&nbsp;&nbsp; &nbsp;position:relative;</li>
<li>&nbsp;&nbsp; &nbsp;width:100%;</li>
<li>&nbsp;&nbsp; &nbsp;height:80px;</li>
<li>&nbsp;&nbsp; &nbsp;background-color:#eee;</li>
<li>&nbsp;&nbsp; &nbsp;text-align:center;</li>
<li>&nbsp;&nbsp; &nbsp;overflow:hidden;</li>
<li>}</li>
<li>#macji .macji-skin{</li>
<li>&nbsp;&nbsp; &nbsp;float:left;</li>
<li>&nbsp;&nbsp; &nbsp;position:relative;</li>
<li>&nbsp;&nbsp; &nbsp;left:50%;</li>
<li>}</li>
<li>#macji .macji-skin li{</li>
<li>&nbsp;&nbsp; &nbsp;position:relative;</li>
<li>&nbsp;&nbsp; &nbsp;right:50%;</li>
<li>&nbsp;&nbsp; &nbsp;float:left;</li>
<li>&nbsp;&nbsp; &nbsp;margin:10px;</li>
<li>&nbsp;&nbsp; &nbsp;padding:0 10px;</li>
<li>&nbsp;&nbsp; &nbsp;border:solid 1px #000;</li>
<li>&nbsp;&nbsp; &nbsp;line-height:60px;</li>
<li>}</li></ol></div>
<div class="runcode">
<p><textarea name="runcode" rows="10" class="runcode_text" id="runcode_z4xrd0">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xml:lang=&quot;zh-cn&quot; lang=&quot;zh-cn&quot; dir=&quot;ltr&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head profile=&quot;http://gmpg.org/xfn/11&quot;&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;meta content=&quot;麦鸡(MacJi)的博客，关注Web内容、结构与表现。&quot; name=&quot;description&quot; /&gt;
&lt;meta content=&quot;Copyright (c) 2008 MacJi&quot; name=&quot;copyright&quot; /&gt;
&lt;meta content=&quot;麦鸡,MacJi&quot; name=&quot;author&quot; /&gt;
&lt;meta content=&quot;web前端开发,麦鸡,MacJi,Blog,博客&quot; name=&quot;keywords&quot; /&gt;
&lt;title&gt;跨浏览器实现float:center，No CSS hacks&lt;/title&gt;
&lt;style&gt;
ul,li{
	margin:0;
	padding:0;
	list-style:none;
}
#macji{
	width:100%;
	height:80px;
	background-color:#eee;
	text-align:center;
	overflow:hidden;
}
#macji .macji-skin{
	float:left;
	position:relative;
	left:50%;
}
#macji .macji-skin li{
	float:left;
	margin:10px;
	padding:0 10px;
	position:relative;
	right:50%;
	line-height:60px;
	border:solid 1px #000;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;跨浏览器实现float:center，No CSS hacks&lt;/h1&gt;
&lt;div id=&quot;macji&quot;&gt;
	&lt;ul class=&quot;macji-skin&quot;&gt;
    	&lt;li&gt;列表一,我是浮动的&lt;/li&gt;
        &lt;li&gt;列表二&lt;/li&gt;
        &lt;li&gt;列表三&lt;/li&gt;
        &lt;li&gt;这里可能是N&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea></p>
<p><input type="button" value="运行代码" class="runcode_button" onclick="runcode_open_new('runcode_z4xrd0');"/> 提示：您可以先修改部分代码再运行</p>
</div>
<p> </p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.welcome58.cn/archives/145/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
