大佬教程收集整理的这篇文章主要介绍了jquery – 删除&害羞;元素中的(软连字符)实体,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直试图用jquery来做这件事.
当我从包含实体的html元素中获取文本时,我似乎得到一个字符串,其中实体被“隐藏”或无法编辑.
你是否必须做一些特别的事情来实际获得包含实体的字符串?
$( document ).ready(function(){ $("button").on("click",function(){ var html = $("div > span").html(); var newHtml = html.replace("­",""); $("div > span").html(newHtml); }); });
div{ max-width: 50px; padding: 10px; border: 1px solid #000; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <span>My text will be hyphe­ned</span> </div> <button> Remove Hyphens </button>
var newHtml = html.replace(/\­/gi,"");
注意:您可能还需要检查­,因为浏览器会将其视为数字,而不是人类友好的字符.
说明:
/(\­)/gi 1st Capturing group (\­) \& matches the character & literally shy; matches the characters shy; literally (case insensitivE) g modifier: global. All matches (don't return on first match) i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
片段
$( document ).ready(function(){ $("button").on("click",function(){ var html = $("div > span").html(); var newHtml = html.replace(/(\­||­)/gi,""); $("div > span").html(newHtml); }); });
div{ max-width: 50px; padding: 10px; border: 1px solid #000; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <span>My text will be hyphe­ned</span> </div> <button> Remove Hyphens </button>
Regex101:https://regex101.com/r/wD3oX7/1
以上是大佬教程为你收集整理的jquery – 删除&害羞;元素中的(软连字符)实体全部内容,希望文章能够帮你解决jquery – 删除&害羞;元素中的(软连字符)实体所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。