我试图隐藏在CMS生成的页面上多次出现的','
(逗号)。在此处查看页面:
http://www.ucd.ie/earth/sandbox/test/01.html
我在标记之前尝试了以下代码(未成功):
<script language="javascript">
var container = $(".hide-comma");
var result = container.html().replace(/,/g, "");
container.html(result);
</script>
答案 0 :(得分:1)
我认为您想替换div中的所有“,”。因此您可以这样做。.在div中获取html,然后替换所有的','
function replaceComma(){
$('#divWithComma').html($('#divWithComma').html().replace(",",""));
console.log('replaced the comma, if you want to see hiding the comma please run the snippet again');
}
function hideComma(){
let text = $('#divWithComma').html();
let stringArray = text.split(',');
let finalHtml = "";
for(let i = 0; i<stringArray.length-1; i++){
finalHtml += stringArray[i] + '<span style="display:none;aria-hidden=true">,</span><p></p>';
}
$('#divWithComma').html(finalHtml);
console.log("yes hide the comma");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='divWithComma'>
<p>,</p>
<input type='button' onclick='replaceComma()' value='replace comma' />
<input type='button' onclick='hideComma()' value='hide comma' />
</div>
答案 1 :(得分:1)
在加载页面完成后输入以下代码:
$('.team-description').each(function(i , v){
var t = $(v).html().replace(/,/g, '');
$(v).html(t);
});