我有两个盒子。我想创建函数,这将给我一些功能。
这就是我所做的:
var showMeRedBox = document.getElementsByClassName('box2_red')[0]
var blackBox = document.getElementsByClassName('box1_black')[0]
var redBox = document.getElementsByClassName('box1_black')[0]
var hideRedBox = document.getElementsByClassName('box2_red')[0]
var showMe = function(show) {
showMeRedBox.style.display = show
}
blackBox.onclick = function() {
showMe('inline-flex');
}
var hideMe = function(hide) {
hideRedBox.style.display = hide
}
blackBox.click = function() { // here should be seocnd click, when I want to hide the red box
hideMe('none');
}
有人给我建议,我该怎么做? 谢谢, 鲇鱼
答案 0 :(得分:0)
您可以使用变量来保存redBox的状态,然后在内部点击询问它:
var isHidden = false;
blackBox.click = function() {
if (isHidden) {
isHidden = false;//show the box
} else {
isHidden = true;
hideMe('none');
}
}
答案 1 :(得分:0)