【问题标题】:Find soft hyphens in HTML document在 HTML 文档中查找软连字符
【发布时间】:2011-11-12 16:40:55
【问题描述】:

我们看下面的代码:

$('#el').html('ex­am­ple');

现在,我怎样才能用软连字符实体取回该元素的文本? 这两个:

$('#el').html(); $('#el').contents().get(0).nodeValue;

给我“示例”作为返回值,而不是“ex­am­ple”

jsFiddle 链接:http://jsfiddle.net/w7QKH/

浏览器:FF7,其他浏览器未勾选。

【问题讨论】:

  • in b4 $('#el').html('ex<wbr>am<wbr>ple');

标签: javascript html soft-hyphen


【解决方案1】:

实际上 $('#el').html() 给你'example' 带有软连字符。如果你运行 $('#el').html().length 它将返回 9。所以连字符在,但它们不显示。而且它不等于 'ex­am­ple' ,因为这个字符串没有被转义。如果你想与字符串进行比较,你应该使用'ex\u00ADam\u00ADple'——这里我用它的unicode值替换了­http://jsfiddle.net/w7QKH/1/

【讨论】:

  • 大起大落!一直在这里拉我的头发!
【解决方案2】:

$('#el').html().replace(/\u00AD/g, '­');

http://jsfiddle.net/K9mUy/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多