如何控制jquery中的Slidetoggle功能
嗨,抱歉这个菜鸟问题,但是这里...我的测试站点上有一个工作幻灯片切换,但是当我单击“幻灯片”按钮时,我希望该按钮更改为“关闭”..然后更改当您单击关闭时返回“幻灯片”...再次抱歉新手问题...这是我的代码..
<script>
/*#boxmove is my button*/
/*.box1 is my sliding panel*/
$('#boxmove').click(function() {
$('.box1').slideToggle('slow', function(showOrHide) {
});
});
</script>
我知道如果我添加以下内容我可以让它显示点击关闭...但我不知道如何“切换”该文本(可能在if/else 语句?)...
<script>
$('#boxmove').click(function() {
$('.box1').slideToggle('slow', function(showOrHide) {
document.getElementById('boxmove').innerHTML = 'close';
});
});
</script>
Hi Sorry for this noob question but here goes...i have a working slidetoggle on a test site of mine, however when i click the "slide" button, i would like that button to change to "close"..and then change back to "slide" when you click close...again sorry for the newbie question.. heres my code..
<script>
/*#boxmove is my button*/
/*.box1 is my sliding panel*/
$('#boxmove').click(function() {
$('.box1').slideToggle('slow', function(showOrHide) {
});
});
</script>
i know if i add the following i can get it to show the close on click...but i dont know how to "toggle" that text (maybe within a if/else statment?)...
<script>
$('#boxmove').click(function() {
$('.box1').slideToggle('slow', function(showOrHide) {
document.getElementById('boxmove').innerHTML = 'close';
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果您使用 jQuery,请完全使用它。要通过 id 访问元素,您可以使用 id 选择器
$('#elementId')
。在
slideToggle
回调中,您可以使用text
jQuery 方法有条件地设置按钮的文本。我正在使用is
jQuery 方法来检查该框是否可见,并根据该方法设置按钮的文本。First of all if you are using jQuery use it completely. To access element by id you can use id selector
$('#elementId')
.Inside the
slideToggle
callback you can usetext
jQuery method to set the text of the button conditionally. I am usingis
jQuery method to check if the box is visible or not and based on that setting the text of the button.