jQuery显示和隐藏在同一链接上 [英] jquery show and hide on same link click

查看:82
本文介绍了jQuery显示和隐藏在同一链接上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,我想在链接单击上显示和隐藏.不是要显示和隐藏的两个不同链接,而只有一个. 我使用过toggle(),但对我不起作用.

I have a div and I want to show and hide on a link click. Not two different links to show and hide but only one. I have used toggle() but its not working for me..

这是代码

<a id="showhidediv">show-hide</a>
<div id="maindiv">
 <div id="innerleftdiv" style="width:49%;float:left">
 </div>
 <div id="innerrightdiv" style="width:49%;float:left">
 </div>
<div>

<script text="text/javascript">
  $().ready(function){
    $("showhidediv").click(function(){
      $("maindiv").hide()
    });
</script>

谢谢

推荐答案

感谢每个人都试图回答这个问题,每个人都是对的.

Thanks every one for trying to answer the question and every one was right..

我找到了解决方案.以下是jQuery函数

I found the solution . The following is the jquery function

$("#showhide").click(function() { 
  if ( $("#maindiv").is(":visible") ) { 
    $("#maindiv").hide(); 
  } else if ( $("#maindiv").is(":hidden") ) { 
    $("#maindiv").show(); 
  }
});

这篇关于jQuery显示和隐藏在同一链接上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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