Jquery - 如何获取样式显示属性“无/块”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1875403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:19:03  来源:igfitidea点击:

Jquery - How to get the style display attribute "none / block"

jquerycoding-styleattributes

提问by Murtaza Mandvi

Is there a way to get the style: display attribute which would have either none or block?

有没有办法获得 style: display 属性,它要么没有要么块?

DIV :

分区:

<div id="ctl00_MainContentAreaPlaceHolder_cellPhone_input_msg_container" class="Error cellphone" style="display: block;">

     <p class="cellphone" style="display: block;">Text</p>

</div>

I know that there is a way to find out if the DIV is hidden or not but in my case this div is dynamically injected so it always shows up as visible false thus I cannot use that :

我知道有一种方法可以找出 DIV 是否隐藏,但在我的情况下,此 div 是动态注入的,因此它始终显示为可见 false,因此我无法使用它:

$j('.Error .cellphone').is(':hidden')

I am able to get the result "display:block" using :

我能够使用以下方法获得结果“显示:块”:

$j('div.contextualError.ckgcellphone').attr('style')

Is there a way to get just the value "block" or "none" or is there a better/more efficient way to do this?

有没有办法只获得值“阻止”或“无”,或者有更好/更有效的方法来做到这一点?

回答by gnarf

You could try:

你可以试试:

$j('div.contextualError.ckgcellphone').css('display')

回答by raphie

If you're using jquery 1.6.2 you only need to code

如果你使用 jquery 1.6.2 你只需要编码

$('#theid').css('display')

for example:

例如:

if($('#theid').css('display') == 'none'){ 
   $('#theid').show('slow'); 
} else { 
   $('#theid').hide('slow'); 
}

回答by Seetpal Singh

this is the correct answer

这是正确答案

$('#theid').css('display') == 'none'

You can also use following line to find if it is display block or none

您还可以使用以下行来查找它是显示块还是无

$('.deal_details').is(':visible')

回答by user2487028

My answer

我的答案

/**
 * Display form to reply comment
 */
function displayReplyForm(commentId) {
    var replyForm = $('#reply-form-' + commentId);
    if (replyForm.css('display') == 'block') { // Current display
        replyForm.css('display', 'none');
    } else { // Hide reply form
        replyForm.css('display', 'block');
    }
}

回答by byrop

//animated show/hide

function showHide(id) {
      var hidden= ("none" == $( "#".concat(id) ).css("display"));
      if(hidden){
          $( "#".concat(id) ).show(1000);
      }else{
          $("#".concat(id) ).hide(1000);
      }
  }