Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery强制删除样式_Jquery - Fatal编程技术网

使用jquery强制删除样式

使用jquery强制删除样式,jquery,Jquery,在我的项目中,通过jquery从某处添加元素样式: 可能是这样的: $('div').removeAttr('style'); $('div').attr('style','width: 200px !important'); $('div').removeAttr('style'); $('div').attr('style','width: 400px !important'); 但现在,我想用我自己的方式: $('div').removeAttr('style'); $('div').

在我的项目中,通过jquery从某处添加元素样式:

可能是这样的:

$('div').removeAttr('style');
$('div').attr('style','width: 200px !important');
$('div').removeAttr('style');
$('div').attr('style','width: 400px !important');
但现在,我想用我自己的方式:

$('div').removeAttr('style');
$('div').attr('style','width: 200px !important');
$('div').removeAttr('style');
$('div').attr('style','width: 400px !important');

但是不起作用(可能是由于文件顺序),我可以为此执行强制removeAttr(“样式”)吗?

最好是完全更新或删除其他代码


否则,您必须确保代码在另一个代码之后运行。因此,您需要对文件进行排序,或者需要将代码连接起来,以响应在其他代码运行之后发生的事件。您无法锁定
样式
属性,并且您已经在使用
!重要信息
,因此您无法创建将覆盖它的样式规则。

删除属性后,您无法将其添加回。您所需要做的就是重写/重新分配样式属性的新值,这最好通过
.css()
方法完成,例如:

$('div').css('width','400px');
更好的方法是:使用
.width()

$('div').width(400);

你试过了吗<代码>$('div')。宽度(400)可能重复的代码,为了进行文件排序,我在正文关闭之前将代码放在index.php中,这应该是顺序的最后一个。@NavinRauniyar:然后,可能另一个代码正在运行,以响应jQuery的
ready
ready
发生在
之前的内联代码之后)甚至是以后的事件,比如
load
@NavinRauniyar:听着,我已经告诉过你需要做什么了。很抱歉,您在执行此操作时遇到问题,但我无法为您找到有问题的代码。如果
ready
还不够晚,请使用一个已经足够晚的事件。使用那些我无法使用的方法!重要规则。首先,使用
!重要信息
是选择器选择错误和/或特殊性的标志。在许多情况下,它的使用可以通过使用其他方法来解决。否则你可能想考虑一下: