作者shyangs (欲翔)
看板Ajax
标题Re: [ js ] 怎麽辨识出HTML中的
时间Thu Jul 16 10:22:17 2009
在 MozTW 问到答案了
http://forum.moztw.org/viewtopic.php?t=27421
"A\u00a0B"==document.getElementById('space').firstChild.nodeValue
为true,详见 MozTW 讨论串。
※ 引述《shyangs (欲翔)》之铭言:
: 我想用 js 辨识 HTML 中的一个文字节点,该节点含有
: 简单的例子
: <html>
: <span id="space">A B</span>
: </html>
: 我试过
: javascript:alert('A B'==document.getElementById('space').firstChild.nodeValue)
: javascript:
: alert('A 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
1F:推 tomin:咦 我用encodeURI()转过 但好像没有一样 07/16 10:37
2F:推 LPH66: 其实是U+00A0 (即'\u00a0') 和空白(U+0020)是不同字 07/16 21:36