jquery按钮单击两个不同div之间切换 [英] Jquery Toggling Between Two Different Divs On Button Click

查看:102
本文介绍了jquery按钮单击两个不同div之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用if else语句禁用jquery函数。
我的问题是我有两个打开onClick的文本框,它们被设置为切换,但我怎样才能设置它,这样如果其中一个框打开,另一个不会打开
我的jquery是

  $(。first1)。on('click',
function(){
$('#suitsyou')。toggle();
}); $($。$ last $')。on('click',
function(){
$('#dealsandoffers')。toggle()
});

可能会更容易看一下我的网站 http://www.jeremyspence.net78.net 它位于软件包选项卡中,您可以看到,当您单击一个选项卡,然后单击另一个选项卡而不关闭首先他们都打开

html是

 < div id =suitsyoustyle =display:none> 

< / div>

< div id =dealsandoffersstyle =display:none>

< / div>

内容不包含在内,所以不要在
<

  $(。)解决方案

第一个)。on('click',function(){
if(!$(#dealsandoffers:visible)。
}
});

如果您需要更多的灵活性,请使用类。这也不是特别用户友好的。在我看来,你想关闭另一个,然后显示当前点击的那个。


How can I disable a jquery function using an if else statement. My problem is that I have two text boxes that open onClick, they are set to toggle, but how can I set it so that if one of the boxes is open, the other one won't open My jquery is

$(".first1").on('click', 
  function () {
    $('#suitsyou').toggle();
  });
$(".last1").on('click', 
  function () {
      $('#dealsandoffers').toggle() 
  });

It may be easier to look at my website http://www.jeremyspence.net78.net it is in the packages tab, you can see that when you click on one tab and then the other without closing the first they both open

the html is

    <div id="suitsyou" style="display:none">

    </div>

    <div id="dealsandoffers" style="display:none"> 

    </div>

Content was not included so not to put so much code in

解决方案

A simple conditional should work:

$(".first").on('click', function () {
    if (!$("#dealsandoffers:visible").length) {
        $("#suitesyou").toggle();
    }
});

Use classes if you need more flexibility than that. This also isn't particularly user friendly. Seems to me like you would want to close the other and then show the one that was currently clicked.

这篇关于jquery按钮单击两个不同div之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆