jQuery .show / .hide / .toggle在某些情况下不起作用

时间:2012-03-24 02:34:23

标签: jquery hide toggle show

我有2个div,我需要连续切换来回显示而不显示。这是我当前的jQuery代码

$(document).ready(function(){

    $('a:link').click(function(){
    $(".surveycontainer").toggle();
    $("#check").toggle();
    });

});

注意#check在页面加载时通过CSS隐藏,所以这个脚本说当点击一个链接时,每个都会被切换,使得“surveycontainer”div消失,“check”div出现,反之亦然。

在调查容器(包含链接)中调用RSS源时,脚本工作正常,单击每个div时,脚本都会切换。在div中放置普通链接时会出现问题,单击“surveycontainer”时会隐藏,但“check”不会显示!

Surveycontainer代码

<div class="surveycontainer" align="left">
<?php
// OFFERS

//Right here is a script that defines $country_code ("US" is what is called when the problem occurs)

<?php if($country_code=="US"): ?>
<a href="http://www.google.com" target="_blank">Yahoo</a>

<?php else: ?>
//Calls a RSS feed containing links here

</div>
<?php endif; ?>

如您所知,$ country_code等于“US”,Google链接会在新窗口中调用。

出于某种原因,当国家/地区代码不等于美国且数据从RSS源中提取时,上面的jQuery脚本会立即显示,并且在单击链接时会切换每个div。但是,当使用Google链接并单击时,只会隐藏“surveycontainer”div并且不会显示“check”。

我迫切需要解决这个问题!非常感谢任何帮助,谢谢!!

1 个答案:

答案 0 :(得分:0)

<?php endif; ?>之前</div>放置surveycontainer div 当满足谷歌链接的条件时。所以重写你的代码看起来像:

<div class="surveycontainer" align="left">
   <?php
   // OFFERS
   //Right here is a script that defines $country_code ("US" is what is called when the problem occurs)
   <?php if($country_code=="US"): ?>
      <a href="http://www.google.com" target="_blank">Yahoo</a>
   <?php else: ?>
       //Calls a RSS feed containing links here
   <?php endif; ?>
</div>