“$$$”字符用于在代码隐藏中获取索引和隐藏列表。现在我想问有没有办法用 jQuery 和/或 JavaScript 隐藏这些字符?
$$$<ul id = "myid"class = "listbranch">
<li>Битола</li>
<li>Скопје</li>
<li>Охрид</li>
<li>Прилеп</li>
<li>Ресен</li>
<li>Гостивар</li>
<li>Куманово</li>
<li>Гевгелија</li>
<li>Штип</li>
<li>Велес</li>
<li>Пробиштип</li>
<li>Тетово</li>
<li>Кочани</li>
<li>Валандово</li>
<li>Струмица</li>
<li>Крива Паланка</li>
<li>Кавадарци</li>
<li>Неготино</li>
</ul>$$$
最佳答案
您可以将它们放入类似 <span class="hide">$$$</span>
的元素中然后使用 JQuery 使用以下代码隐藏元素,
//hide the element with the hide class
$(".hide").hide();
另一个解决方案是将 $$$ 包装在 span 标记中,并使用 css 隐藏它们,如 user5295483 评论所建议的。不过,我建议使用类名,以防万一您不想隐藏所有 span 标签。
HTML:
<span>$$$</span>
CSS:
span{
display:"none";
}
/* use this class if you don't want to hide all span tags*/
.hide{
display:"none";
}
如果你想使用纯 JavaScript 隐藏 $$$ ?您可以尝试以下方法:
//Call the hide function,
//the $ must be escaped so that regexp will pick up all three of them
hide(/\$\$\$/);
function hide(text) {//begin function
//create a new RegExp object with the global replacement flag
var search = new RegExp(text,"g");
//wrap the $$$ with a span element
document.body.innerHTML = document.body.innerHTML.replace(search, "<span class='hide'>$$$$$$</span>");
//store the collection of elements with the hide class
var collection = document.getElementsByClassName("hide");
//loop through the collection
for (var i = 0; i < collection.length; i++) {//begin for loop
//hide the element
collection[i].style.display = "none";
}//end for loop
}//end function
关于javascript - 有没有办法隐藏起点上的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35940469/