如何控制jquery中的Slidetoggle功能

发布于 2024-12-29 08:10:41 字数 611 浏览 2 评论 0原文

嗨,抱歉这个菜鸟问题,但是这里...我的测试站点上有一个工作幻灯片切换,但是当我单击“幻灯片”按钮时,我希望该按钮更改为“关闭”..然后更改当您单击关闭时返回“幻灯片”...再次抱歉新手问题...这是我的代码..

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不美如何 2025-01-05 08:10:41

首先,如果您使用 jQuery,请完全使用它。要通过 id 访问元素,您可以使用 id 选择器 $('#elementId')

slideToggle 回调中,您可以使用 text jQuery 方法有条件地设置按钮的文本。我正在使用 is jQuery 方法来检查该框是否可见,并根据该方法设置按钮的文本。

$('#boxmove').click(function() {
      $('.box1').slideToggle('slow', function(showOrHide) {
          $('#boxmove').text($(this).is(':visible')? 'slide' : 'close');          
      });
});

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 use text jQuery method to set the text of the button conditionally. I am using is jQuery method to check if the box is visible or not and based on that setting the text of the button.

$('#boxmove').click(function() {
      $('.box1').slideToggle('slow', function(showOrHide) {
          $('#boxmove').text($(this).is(':visible')? 'slide' : 'close');          
      });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文