jQuery插件正在应用内联样式(display:block)。我感觉很懒,想用display:none重写它。

最好的(懒惰的)方法是什么?


当前回答

删除内联样式(由jQuery生成)最简单的方法是:

$(this).attr("style", "");

内联代码应该消失,对象应该适应CSS文件中预定义的样式。

为我工作!

其他回答

美元el.css ({ 高度:", 'margin-top': " });

等等……

只需要保留第二个参数为空!

我有类似的问题与宽度属性。我不能从代码中删除!important,因为它在一个新模板上需要这种样式,我添加了一个Id (modalstyles)到元素中,然后我添加了以下代码到模板中:

<script type="text/javascript">
    $('#modalstyling').css('width', '');    //Removal of width !important
    $('#modalstyling').width('75%');        //Set custom width
</script>
$('div[style*=block]').removeAttr('style');

下面是我编写的插入jQuery的inlineStyle选择器过滤器。

$("div:inlineStyle(display:block)") // will select all divs with an inline style of display: block set

在你的例子中,你可以这样使用:

$("div:inlineStyle(display:block)").hide();

如果显示是你的样式中唯一的参数,你可以运行这个命令来删除所有的样式:

$('#element').attr('style','');

这意味着如果你的元素之前是这样的:

<input id="element" style="display: block;">

现在你的元素看起来是这样的:

<input id="element" style="">