简体   繁体   English

选项卡处于活动状态时(隐藏)隐藏和显示div

[英]Hide and Show a div when a tab is active ( selected )

I have this tabs built. 我建立了这个标签。

When I click on Round Trip, I want to make disappear that Flight 2 form. 当我单击“往返”时,我想使Flight 2表格消失。

But since that is needed on multi-city, I want it to show back on 但是由于在多城市中需要这样做,所以我希望它能再次显示出来

multi-city. 多城市。

在此处输入图片说明

I used this 我用这个

jQuery('#rdbOneWay').attr("class","onewaybuttonchecked");
jQuery('#rdbRoundTrip').attr("class","roundwaybuttonchecked");  
jQuery('#rdbMultiCity').attr("class","multiwaybuttonchecked");  

jQuery('.ret_date_block').attr("id","noreturndate");    


   $("#noreturndate").hide();
$(".onewaybuttonchecked").on("click", function(){
    $("#noreturndate").hide();
});

      $(".roundwaybuttonchecked").on("click", function(){
    $("#noreturndate").show();
});

          $(".multiwaybuttonchecked").on("click", function(){
    $("#noreturndate").show();
});

});

I used this to hide something on the One Way tab. 我用它来隐藏“单向”选项卡上的内容。 If: 如果:

$(".roundwaybuttonchecked").on("click", function(){
    $("#noreturndate").show();
});

If I use here the correct id of Flights 2 to hide it on the Round-Trip, it does its job but when I switch between One-Way and Round-Trip it shows nothing. 如果在这里使用航班2的正确ID将其隐藏在往返行程中,它将完成其工作,但是当我在单向和往返行程之间切换时,它什么也没有显示。 This line get's in action when I go from Multi City to Round-Trip. 从多城市到往返旅行时,这条线生效。

Any ideas? 有任何想法吗?

You definitely need a conditional in here. 您肯定在这里需要一个条件。

In your JQuery function, try something like this: 在您的JQuery函数中,尝试执行以下操作:

function radioButton() {
if (document.getElementById('htmlElement1').checked) {
    document.getElementById('htmlElement2').style.visibility = 'visible';
} else {
    document.getElementById('htmlElement').style.visibility = 'hidden';
}

Please note that since I cannot view your HTML - I am not sure what elements you are using so where i say htmlElement 1 (or 2) please fill that in with the appropriate elements. 请注意,由于我无法查看您的htmlElement 1 (or 2)我不确定您使用的是什么元素,因此在我说htmlElement 1 (or 2)请用适当的元素填充。

Let me know you results! 让我知道你的结果!

Never mind. 没关系。

I used same code as above 我使用了与上面相同的代码

jQuery('#rdbOneWay').attr("class","onewaybuttonchecked");
jQuery('#rdbRoundTrip').attr("class","roundwaybuttonchecked");  
jQuery('#rdbMultiCity').attr("class","multiwaybuttonchecked");  

jQuery('.pnlFlight2').attr("id","pnlFlight2");  


   $("#pnlFlight2").hide();
$(".onewaybuttonchecked").on("click", function(){
    $("#pnlFlight2").hide();
});

      $(".roundwaybuttonchecked").on("click", function(){
    $("#pnlFlight2").hide();
});

          $(".multiwaybuttonchecked").on("click", function(){
    $("#pnlFlight2").show();
});

and it did the trick, I don't know why it didn't work earlier but glad it did now. 它成功了,我不知道为什么它不能更早地发挥作用,但现在却高兴了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM