简体   繁体   English

使用内联CSS覆盖jquery hide()

[英]override jquery hide() using inline css

HTML 的HTML

<div class="dep-adm-inp" <?php if(!empty($adm_f) || $adm_f != "") echo "style='display:block'"; ?> id="fees-inp">
    <label>Admission Fees(<i class="fa fa-inr"></i>)</label>
    <div class="input-group">
        <span class="input-group-addon remove-inp"><i class="fa fa-close"></i></span>
        <input type="text" class="form-control expected" value="<?php if(!empty($adm_f)) echo $adm_f; ?>" placeholder="Amount Expected">
        <input type="text" class="form-control paid" value="<?php if(!empty($adm_f)) echo $adm_f; ?>" placeholder="Paid Amount">
    </div>
</div>

Javascript Java脚本

$(".dep-adm-inp").hide();

the div is hidden when page loads but if the php variable is not empty then i want to show the div when. 页面加载时div是隐藏的,但是如果php变量不为空,那么我想在什么时候显示div。

set the class variable dep-adm-inp as hidden by default in css. 在CSS中将类变量dep-adm-inp为默认隐藏。 If the variable $adm_f is not empty, set style='display:block;' 如果变量$adm_f不为空,则设置style='display:block;' . With this logic you don't need to call the statement $(".dep-adm-inp").hide(); 通过这种逻辑,您无需调用语句$(".dep-adm-inp").hide(); in your javascript. 在您的JavaScript中。 This way the div will be shown only if the variable $adm_f is not empty. 这样,仅当变量$adm_f不为空时才显示div。

.hide() method sets display:none; .hide()方法设置display:none; on your element. 在你的元素上。 You can override it by setting display: block!important; 您可以通过设置display: block!important;来覆盖它display: block!important; (or whatever your display property is) in CSS: (或其他display属性)在CSS中:

 setTimeout(() => { $('.item').hide(); }, 2000); 
 .container { display: flex; } .item { width: 200px; height: 100px; background-color: darkgoldenrod; margin: 10px; } /* This makes .item visible even after .hide() */ .item-visible { display: block!important; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container"> <div class="item item-visible">Will be visible</div> <div class="item">Will be hidden</div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM