Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在HTML文档中查找软连字符_Javascript_Html_Soft Hyphen - Fatal编程技术网

Javascript 在HTML文档中查找软连字符

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('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,未在其他浏览器中选中。

$(“#el').html()。替换(/\u00AD/g,“­;”)


请参见

实际上是$('#el')。html()提供了带有软连字符的
'example'
。如果运行$('#el').html().length,它将返回9。因此,连字符在中,但不显示。而且它不等于
'ex­;am­;ple'
,因为此字符串未转义。如果要与字符串进行比较,应该使用
'ex\u00ADam\u00ADple'
-这里我替换了
­及其unicode值

在b4
$('#el').html('example')大人物!我一直在这里拉扯我的头发@谢谢你!