我们来看下面的代码:
$('#el').html('example');
现在,我怎样才能用软连字符实体取回该元素的文本?这两个:
$('#el').html(); $('#el').contents().get(0).nodeValue;
给我“example”作为返回值,而不是“example”
jsFiddle 链接:http: //jsfiddle.net/w7QKH/
浏览器:FF7,其他浏览器未勾选。
我们来看下面的代码:
$('#el').html('example');
现在,我怎样才能用软连字符实体取回该元素的文本?这两个:
$('#el').html(); $('#el').contents().get(0).nodeValue;
给我“example”作为返回值,而不是“example”
jsFiddle 链接:http: //jsfiddle.net/w7QKH/
浏览器:FF7,其他浏览器未勾选。
实际上 $('#el').html() 给你'example'
软连字符。如果你运行 $('#el').html().length 它将返回 9。所以连字符在,但它们不显示。而且它不相等'ex­am­ple'
,因为这个字符串没有被转义。如果你想与你应该使用的字符串进行比较'ex\u00ADam\u00ADple'
- 这里我­
用它的 unicode 值替换。http://jsfiddle.net/w7QKH/1/
$('#el').html().replace(/\u00AD/g, '­');