当我单击锚标记时,此代码会出现额外的段落,但我不希望所有这些函数因为它变得混乱我想知道如何将这段代码压缩成一个函数我不介意 jquery,但我更喜欢 javascript,但只做更有效的事情。
function showmore1()
{
var more_1 = document.getElementById("learnmore_1");
if (more_1.style.display == "block")
{
more_1.style.display = "none";
document.getElementById('showmore_1').innerHTML ='<a>Even More History</a>';
}
else
{
more_1.style.display = "block";
document.getElementById('showmore_1').innerHTML ='<a>Show Less</a>';
}
}
function showmore2()
{
var more_2 = document.getElementById("learnmore_2");
if (more_2.style.display == "block")
{
more_2.style.display = "none";
document.getElementById('showmore_2').innerHTML ='<a>Even More Why programming</a>';
}
else
{
more_2.style.display = "block";
document.getElementById('showmore_2').innerHTML ='<a>Show Less</a>';
}
}
function showmore3()
{
var more_3 = document.getElementById("learnmore_3");
if (more_3.style.display == "block")
{
more_3.style.display = "none";
document.getElementById('showmore_3').innerHTML ='<a>Even More Skills</a>';
}
else
{
more_3.style.display = "block";
document.getElementById('showmore_3').innerHTML ='<a>Show Less</a>';
}
}
function showmore4()
{
var more_4 = document.getElementById("learnmore_4");
if (more_4.style.display == "block")
{
more_4.style.display = "none";
document.getElementById('showmore_4').innerHTML ='<a>Even More Accomplishments</a>';
}
else
{
more_4.style.display = "block";
document.getElementById('showmore_4').innerHTML ='<a>Show Less</a>';
}
}