當我單擊一個錨標記時,此代碼會顯示額外的段落,但我不想要所有這些函數,因爲它會變得雜亂我想知道如何壓縮這個代碼到一個單一的功能我不介意jQuery,但我更喜歡JavaScript,但只是做什麼更有效。如何將所有這些函數壓縮到一個函數中 - 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>';
}
}
這個問題會更appropiate上http://codereview.stackexchange.com – Matt