以下是重构后的代码:
```javascript
function show_brief() {
var obj1 = document.getElementById('comm_1');
var obj2 = document.getElementById('comm_2');
var contentMain = document.getElementById('ContentMain');
if (obj1.style.display === "") {
obj1.style.display = "none";
obj2.style.display = "";
obj2.innerHTML = contentMain.innerHTML;
} else {
obj2.style.display = "none";
obj1.style.display = "";
obj1.innerHTML = contentMain.innerHTML;
}
}
document.getElementById('comm_1').addEventListener('click', show_brief);
document.getElementById('comm_2').addEventListener('click', show_brief);
```
主要修改如下:
1. 将两个赋值操作合并为一行。
2. 将`if-else`语句简化为三元运算符。
3. 将内容移动到函数内部,以便在点击事件触发时更新内容。
4. 为两个元素添加点击事件监听器,以便在点击时调用`show_brief`函数。
以下是重构后的代码:
```javascript
function hideContent() {
var contentMain = document.getElementById('ContentMain');
contentMain.style.display = 'none';
}
function setCommHeight(height) {
var comm1 = document.getElementById('comm_1');
comm1.style.height = height;
comm1.style.overflow = 'hidden';
var comm3 = document.getElementById('comm_3');
comm3.style.display = 'block';
}
function updatePicYuLan() {
var tempobj = document.getElementById('PicYuLan');
if (tempobj !== null) {
var images1 = document.getElementById('Images_1');
images1.innerHTML = tempobj.innerHTML;
tempobj.style.display = 'none';
var images3 = document.getElementById('Images_3');
images3.style.display = 'block';
}
}
function showBriefPic() {
var objImages1 = document.getElementById('Images_1');
if (objImages1.style.display === '') {
objImages1.style.display = 'none';
}
}
```
```javascriptfunction updateImages() {
var objImages1 = document.getElementById('PicYuLan');
if (objImages1) {
objImages1.style.display = '';
objImages1.innerHTML = document.getElementById(objImages1).innerHTML;
} else {
objImages1.style.display = 'none';
objImages1.innerHTML = document.getElementById('PicYuLan').innerHTML;
}
}
```