(jQuery)切换div样式“display:none”到“display:inline” [英] (jQuery) Toggle div style "display:none" to "display:inline"

查看:524
本文介绍了(jQuery)切换div样式“display:none”到“display:inline”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个div,我希望能够在它们之间切换onClick按钮(目前使用.toggle();)

显示div在页面上是div1。这个div的风格是'display:inline'。
我的其他div(div2)以'display:none'开始。



当div1切换到div2时,我希望div2具有显示:内联。



编辑:这是工作:

  $(function(){
$('#button')。click(function(){
$ b $('#div1')。toggleClass('hide'); $ b $('#div2')。('。hidden')){
$ b $('#div2')。removeClass('hidden');
$('#div2')。addClass('show');


}
else {

$('#div2' ).addClass('hidden');
$('#div2')。removeClass('show');


}


});
});


解决方案

我会使用 .toggleClass() display:inline ; display:block;



创建一个隐藏的内联类,那些。


I have 2 divs which and I want to be able to toggle between them onClick of a button (currently using .toggle();)

The div that shows on the page is div1. This div has the style 'display:inline'. My other div (div2) starts with the style 'display:none'.

When the div1 switches to div2, I want div2 to have the style of "display:inline". How do I do this?

EDIT: This is working:

$(function(){
  $('#button').click(function(){

    $('#div1').toggleClass('hide');

if ($('#div2').is('.hidden')) {

          $('#div2').removeClass('hidden');
          $('#div2').addClass('show');


      }
      else{

          $('#div2').addClass('hidden');
          $('#div2').removeClass('show');


      }


  });
});

解决方案

I would use .toggleClass() as toggle switches between display: inline; and display: block;

Create a hidden and inline class and just toggle those.

这篇关于(jQuery)切换div样式“display:none”到“display:inline”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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