[問題] element.setAttributeNS 用法
我對 xml namespace 有疑問,不明白 setAttributeNS 的用法。
這問題也 po 在 MozTW 討論區:
http://forum.moztw.org/viewtopic.php?p=153303
有附一個 xul 文件為例子,抱歉請用 Firefox 測試)
範例文件中,xul:window 元素有一個 title 屬性,用來改變視窗顯示的標題:
https://developer.mozilla.org/en/XUL/window#a-title
我原本的目的是「動態改視窗標題」
範例檔的 Btn 1, Btn 2 都是執行 setAttribute,
效果一如預期,視窗標題有改變;
不解的是把滑鼠移到第一行的 <html:p> 時,會看到 tooltip 文字跳出來。
以我的知識,不知是否為 Bug 257780 相似情況,
https://bugzilla.mozilla.org/show_bug.cgi?id=257780
title 被錯誤地用作 tooltip
而 html 元素在沒有 title 時,應該找相關父元素的 title 來用
(離題:倒是可以設 title=" " 避免沿用),但 window 不是 html 元素啊。
於是第一個問題:
title 的值可以用 element.setAttribute('title', value) 設定。
若改用 element.setAttributeNS(namespace, 'title', value)
是否更明確指出我要設的是 xul:title?
第二個問題:
嘗試按 Btn 3, 4, 5, 6 都無法改變視窗標題,我是否 namespace 參數根本寫錯了?
開 Firebug 發現這些 Btn 都會讓 window 元素多出 title 屬性、
甚至複數的 title 屬性……
而執行 win.hasAttributeNS(ns.xul, 'title');(變數請見原始碼)時,
只有 Btn 5, 6 為 true;
執行 win.hasAttribute('title'); 則剩下 Btn 5 結果為 true。
我的理解是 Btn 1, 2, 5 做的事情:
setAttribute 和 setAttributeNS(ns.xul, ...) 是相同的,
都成功設了 xul:title 這個屬性;
然而視窗標題都沒變,實在不解。
寫得好亂,其實如果能解釋一下 setAttributeNS 的用例
我應該會比較清楚。甚至告訴我那個檔案 我到底在做什麼,也相當感謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.194.88.12
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章