Re: [ js ] 怎麼辨識出HTML中的  

看板Ajax作者 (欲翔)時間15年前 (2009/07/16 10:22), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串2/2 (看更多)
在 MozTW 問到答案了 http://forum.moztw.org/viewtopic.php?t=27421 "A\u00a0B"==document.getElementById('space').firstChild.nodeValue 為true,詳見 MozTW 討論串。 ※ 引述《shyangs (欲翔)》之銘言: : 我想用 js 辨識 HTML 中的一個文字節點,該節點含有&nbsp; : 簡單的例子 : <html> : <span id="space">A&nbsp;B</span> : </html> : 我試過 : javascript:alert('A B'==document.getElementById('space').firstChild.nodeValue) : javascript: : alert('A&nbsp;B'==document.getElementById('space').firstChild.nodeValue) : : javascript:alert('A%20B'==document.getElementById('space').firstChild.nodeValue) : : javascript: : alert('A\u0020B'==document.getElementById('space').firstChild.nodeValue) : 答案都是false,怎樣寫才會是true : 環境:Fx3.5、xp sp3 : 謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.175.199.170

07/16 10:37, , 1F
咦 我用encodeURI()轉過 但好像沒有一樣
07/16 10:37, 1F

07/16 21:36, , 2F
&nbsp;其實是U+00A0 (即'\u00a0') 和空白(U+0020)是不同字
07/16 21:36, 2F
文章代碼(AID): #1ANexSRj (Ajax)
文章代碼(AID): #1ANexSRj (Ajax)