Javascript 滑动元件不会向后滑动

Javascript 滑动元件不会向后滑动,javascript,javascript-events,elements,sliding,Javascript,Javascript Events,Elements,Sliding,嗨,我正在制作一个表单,其中有一个复选框,如果选中,将向下滑动更多选项。如果不加控制,它会向上滑动 对函数的调用工作一轮,即在选中时向下滑动,在取消选中时向上滑动,但不会向上滑动 请帮我想一想怎么做 **注意:我不知道jQuery,现在不想花时间学习它 <form> <table> rows and cells here THIS IS THE CHECKBOX TO SHOW HIDDEN TABLE --> <input type="checkbox" n

嗨,我正在制作一个表单,其中有一个复选框,如果选中,将向下滑动更多选项。如果不加控制,它会向上滑动

对函数的调用工作一轮,即在选中时向下滑动,在取消选中时向上滑动,但不会向上滑动

请帮我想一想怎么做

**注意:我不知道jQuery,现在不想花时间学习它

<form>
<table>
rows and cells here
THIS IS THE CHECKBOX TO SHOW HIDDEN TABLE --> <input type="checkbox" name="booking" class="field" value="booking" onclick="show_booking('booking',200,5)"/> Check here for booking
</table>
<table id="booking">
HIDDEN rows and cells here
</table>
</form>

 ******************JAVASCRIPT*********************

function show_booking(obj, heightOpen, heightClose){
    if(document.getElementById(obj).style.height <= 6 ){
        animateDown(document.getElementById(obj),heightOpen);
    }
    else {
        animateUp(document.getElementById(obj), heightClose);

    }
}

function animateDown(obj, height){

       var obj_height = obj.clientHeight;

       if(obj_height >= height){ return;}               
       else {
           obj.style.height = (obj_height + 5) + "px";
           setTimeout(function(){
               animateDown(obj, height);
           }, 25)
       }
}


function animateUp (obj, height){

       var obj_height = obj.style.height.substring(0,2);
        if(obj_height >= height){    obj.style.height = (obj_height - 5) + "px";
           setTimeout(function(){
               animateUp(obj, height);
           }, 200)}   
       else { return; }         
       }    

这里的行和单元格
这是用于显示隐藏表-->此处检查预订的复选框
此处隐藏行和单元格
******************JAVASCRIPT*********************
功能显示\预订(obj、高度打开、高度关闭){
if(document.getElementById(obj.style.height=height){return;}
否则{
obj.style.height=(obj_height+5)+“px”;
setTimeout(函数(){
动画向下(对象,高度);
}, 25)
}
}
函数animateUp(对象、高度){
var obj_height=obj.style.height.substring(0,2);
如果(对象高度>=高度){obj.style.height=(对象高度-5)+“px”;
setTimeout(函数(){
animateUp(对象,高度);
}, 200)}   
else{return;}
}    

您确实在尝试根据复选框是否选中来执行操作,因此为什么不使用复选框的checked属性:

<input onclick="show_booking.apply(this, ['booking', 200, 5])" type="checkbox" name="booking" class="field" value="booking" 

if(document.getElementById(obj).style.height对你来说太棒了,这个网站的成员的知识水平总是让我感到惊讶。非常感谢。是的,应该使用input.checked来显示/隐藏表格。而不是设置“style.height”,你应该将style.display改为block/none。高度可能会导致不同浏览器之间出现问题。
function show_booking(obj, heightOpen, heightClose){
    if(this.checked) {
        animateDown(document.getElementById(obj),heightOpen);
    } 
    else {
        animateUp(document.getElementById(obj), heightClose);
    }
}