Archive for the ‘(X)HTML’ Category

瀏覽器差異: <button> 標籤的預設行為

星期日, 九月 28th, 2008

<button> 是 form 元素之一,其中的屬性 type 可用的值有 submit、reset、button,預設值是 submit,其效果等同於 <input>:
1. <button type="submit">submit</button> 等同於 <input type="submit">
2. <button type="reset">reset</button> 等同於 <input type="reset">
3. <button type="button">abc</button> 等同於 <input type="button" value="abc">

可是當 <button> 沒有指定 type 時,依據 W3C 的規範,預設等同於 submit,但是在 IE7 下,卻是等同於 button。

for Internet Explorer 7
<button>abc</button> 等同於 <input type="button" value="abc">

for Mozilla Firefox 3
<button>abc</button> 等同於 <input type="submit" value="abc">

因此,如下的表單在 IE 7 與 FF 3 下會有全然不同的行為:

<form method="get">
<input name="yourname" value="WhoAmI"><button onclick="NameCheck();">check</button>
<input type="submit" value="send">
</form>

原本預期按下 <button> check 之後,會執行 NameCheck() 函式。
在 IE 7 下會如期運作,但在 FF 3 下,這個表單會直接送出。

因此在使用 <button> 時,建議要指定 type 屬性,以免效果不如預期。

XHTML 規則小結 – 節錄自 ISBN 957-442-178-3

星期二, 四月 17th, 2007

節錄自 跨平台網頁設計 使用 Web 標準技術 ISBN 957-442-178-3 旗標出版

    XHTML 規則小結

  • 在網頁開頭處,加入適當的 DOCTYPE 與名稱領域。
  • 使用 META Content 元素,宣告網頁所用的字元編碼。
  • 所有元素與屬性名稱皆必須為小寫字母。
  • 所有屬性值必須加上引號。
  • 所有屬性值皆必須有屬性值。
  • 所有標記皆必須有結束部分。
  • 對於不含內容的標記,必須在結尾處加上空白字元與斜線符號。
  • 註解內不可使用連續兩個破折號。
  • 小於符號(<)必須以 &lt; 來編碼,& 符號必須以 &amp; 來編碼。

更換網址列的圖檔

星期日, 六月 25th, 2006

語法很簡單,只要在網頁的 head 區塊加入以下的語法即可:
<link href="xxx.ico" mce_href="xxx.ico" rel="shortcut icon" type="image/x-icon" />
其中 xxx.ico 就是網址列的圖檔,通常會放在網站根目錄並命名為 favicon.ico。

如果圖檔是位在 image 目錄下,並名為 abc.ico,則語法是:
<link href="image/abc.ico" mce_href="image/abc.ico" rel="shortcut icon" type="image/x-icon" />

如果圖檔放在其他的網站下,例如 http://www.abc.com/xyz.ico,則語法為:
<link href="http://www.abc.com/xyz.ico" mce_href="http://www.abc.com/xyz.ico" rel="shortcut icon" type="image/x-icon" />