滑动元件不会滑落
我正在制作一个带有复选框的表单,如果选中该复选框,则会向下滑动更多选项,如果未选中,则会向上滑动。
对函数的调用有效一轮 IE 在选中时向下滑动,在取消选中时向上滑动,但不会向上滑动。
请帮我弄清楚如何进行这项工作。
**注意:我不了解 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; }
}
I'm making a form that has a checkbox that if checked will slide down some more options, and unchecked it will slide up.
The call to the function works one round I.E. slide down on check and up on uncheck but wont slide back up.
Please help me figure out how to make this work.
**NOTE: I don't know jQuery and don't want to invest the time to learn it at this point.
<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; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您实际上是在尝试根据复选框是否被选中来采取行动,所以为什么不使用复选框的选中属性:
apply
将函数内部的this
值设置为第一个争论。因此,在show_booking
this
内部将是刚刚单击的复选框。现在您可以更简单地编写该函数,例如:You're really trying to act based on whether the checkbox is checked, so why not use the checkbox's checked property:
apply
sets thethis
value inside of the function to the first argument. So inside ofshow_booking
this
will be the checkbox that was just clicked. Now you can more simply write the function like: