-4
如何将所有这些转换为所有div都具有类而不是id? 我在这个世界上,现在只是复制粘贴代码,学习是新...在JavaScript中将id转换为类
<div id="LEGEND">abB</div>
<div id="small-a" style="display: none;">This is small-a</div>
<div id="small-b" style="display: none;">This is small-b</div>
<div id="big-a" style="display: none;">This is big-a</div>
<div id="big-b" style="display: none;">This is big-b</div>
<script>
function showElement(id) {
document.getElementById(id).style.display = "block";
}
window.onload = function ShowHide() {
var legend = document.getElementById("LEGEND").innerHTML;
if(legend.indexOf("a") != -1) showElement("small-a");
if(legend.indexOf("b") != -1) showElement("small-b");
if(legend.indexOf("A") != -1) showElement("big-a");
if(legend.indexOf("B") != -1) showElement("big-b");
}
</script>
为什么要转换它? – Amy
在记事本中打开文件。按下Ctrl + H。在查找文本框中键入'id =“'在替换为文本框中键入'class =”'。点击全部替换。关闭对话框并保存文件。 –
把'.textContent'放在'.indexOf'之前。你没有类的元素,你的第一句话不清楚,所以我不知道你需要什么。 –