Javascript 在HTML文档中查找软连字符
让我们看一下以下代码: $('#el').html('ex­am­ple'); $('el').html('ex­;am­;ple'); 现在,如何使用软连字符实体返回该元素的文本? 这两项: $('#el').html(); $('#el').contents().get(0).nodeValue; $('#el').html(); $('#el').contents().get(0).nodeValue; 将“示例”作为返回值,而不是“ex­;am­;ple” JSIDLE链接: 浏览器:FF7,未在其他浏览器中选中。Javascript 在HTML文档中查找软连字符,javascript,html,soft-hyphen,Javascript,Html,Soft Hyphen,让我们看一下以下代码: $('#el').html('ex­am­ple'); $('el').html('ex­;am­;ple'); 现在,如何使用软连字符实体返回该元素的文本? 这两项: $('#el').html(); $('#el').contents().get(0).nodeValue; $('#el').html(); $('#el').contents().get(0).nodeValue; 将“示例”作为返回值,而不是“ex­
$(“#el').html()。替换(/\u00AD/g,“­;”)代码>
请参见实际上是$('#el')。html()提供了带有软连字符的'example'
。如果运行$('#el').html().length,它将返回9。因此,连字符在中,但不显示。而且它不等于'ex­;am­;ple'
,因为此字符串未转义。如果要与字符串进行比较,应该使用'ex\u00ADam\u00ADple'
-这里我替换了­代码>及其unicode值 在b4$('#el').html('example')代码>大人物!我一直在这里拉扯我的头发@谢谢你!