我如何改变CSS显示无或块属性使用jQuery?


当前回答

用这个:

$("#id").(":display").val("block");

Or:

$("#id").(":display").val("none");

其他回答

在javascript中:

document.getElementById("myDIV").style.display = "none";

在jquery中:

$("#myDIV").css({display: "none"});
$("#myDIV").css({display: "block"});

你可以用:

$('#myDIV').hide();
$('#myDIV').show();

你可以按按钮

<按钮onclick " . getelementbyid .style(“elementid”)。Display = 'none or block';" >

(function($){
    $.fn.displayChange = function(fn){
        $this = $(this);
        var state = {};
        state.old = $this.css('display');
        var intervalID = setInterval(function(){
            if( $this.css('display') != state.old ){
                state.change = $this.css('display');
                fn(state);
                state.old = $this.css('display');
            }
        }, 100);        
    }

    $(function(){
        var tag = $('#content');
        tag.displayChange(function(obj){
            console.log(obj);
        });  
    })   
})(jQuery);

在我的例子中,我根据输入元素是否为空来显示/隐藏表单的元素,因此在隐藏元素时,隐藏元素后面的元素被重新定位,占用了它的空间,因此有必要做一个float:这样的元素的元素的左侧。即使使用插件作为依赖,也必须使用float。

$ (" # id ") . css(“显示”,“没有一个”);

setTimeout (() = > { $ (" # id ") . css(“显示”,“没有一个”); },2000) $ (" # id2) . css(“显示”,“没有一个”); < script src = " https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js " > < /脚本> <div id='id'>Hello World!< / div > <div id='id2'>Hello World 2!< / div >