我需要优化我编写的代码。单击相关按钮后,有 04 个不同的 DIV ID 需要显示/隐藏。请帮我优化这个 Javascript 代码:
function missionShowHide()
{
var mis_element = document.getElementById('mission');
var news_element = document.getElementById('news');
var serv_element = document.getElementById('server');
var field_element = document.getElementById('field');
var mis = mis_element.style;
if(mis.display == 'none') {mis.display = 'block';
news_element.style.display='none';
serv_element.style.display='none';
field_element.style.display='none';
}
else
{
mis.display = 'block';
news_element.style.display='none';
serv_element.style.display='none';
field_element.style.display='none';
}
}
function newsShowHide()
{
var mis_element = document.getElementById('mission');
var news_element = document.getElementById('news');
var serv_element = document.getElementById('server');
var field_element = document.getElementById('field');
var news = news_element.style;
if(news.display == 'none') {news.display = 'block';
mis_element.style.display='none';
serv_element.style.display='none';
field_element.style.display='none';
}
else
{
news.display = 'block';
mis_element.style.display='none';
serv_element.style.display='none';
field_element.style.display='none';
}
}