jQuery的 – 如何获得样式显示属性“无/块”
有没有一种方法来获得样式:显示属性,它可以没有或阻止?
DIV:
<div id="ctl00_MainContentAreaPlaceHolder_cellPhone_input_msg_container" class="Error cellphone" style="display: block;"> <p class="cellphone" style="display: block;">Text</p> </div> 我知道有一种方法来找出DIV是否隐藏,但在我的情况下,这个div是dynamic注入的,所以它总是显示为可见的错误,因此我不能使用:
 $j('.Error .cellphone').is(':hidden') 
我能够得到结果“显示:块”使用:
 $j('div.contextualError.ckgcellphone').attr('style') 
有没有办法只获得“块”或“无”的价值,或者有没有更好/更有效的方法来做到这一点?
你可以尝试:
 $j('div.contextualError.ckgcellphone').css('display') 
如果你使用jQuery 1.6.2,你只需要编码
 $('#theid').css('display') 
例如:
 if($('#theid').css('display') == 'none'){ $('#theid').show('slow'); } else { $('#theid').hide('slow'); } 
这是正确的答案
 $('#theid').css('display') == 'none' 
您也可以使用下面的一行来查找它是否是显示模块
 $('.deal_details').is(':visible') 
我的答案
 /** * 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'); } }