Javascript 使用 jquery 编辑现有的内联样式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8359224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 05:40:41  来源:igfitidea点击:

edit existing inline style using jquery?

javascriptjqueryinternet-explorer

提问by PD24

I have some html which seems to default to :

我有一些 html 似乎默认为:

<ul style="top: 72px; visibility: hidden;">

But i need Jquery to rescue me and change top: 72px to top: 37px

但我需要 Jquery 来拯救我并将 top: 72px 更改为 top: 37px

Is this possible? as in Firefox 37px seems to show up but in IE7 it shows up as 72px

这可能吗?如在 Firefox 中 37px 似乎显示但在 IE7 中显示为 72px

Thanks

谢谢

edit: added more info

编辑:添加了更多信息

the ul id = treemenu1

ul id = treemenu1

and its parent element is div class = treemenu

并且它的父元素是 div class = treemenu

回答by Chad

$('#treemenu1').css({ top: 37 });

Should work fine.

应该工作正常。

jsFiddleof POC.

POC 的jsFiddle

回答by Adam Rackis

I would select your ul by id:

我会通过 id 选择你的 ul:

$("#treemenu1").css("top", "37px");

Also note that you can update multiple css properties at once by passing an object in, whose keys and values correspond to css properties, and their new values:

另请注意,您可以通过传入一个对象(其键和值对应于 css 属性及其新值)来一次更新多个 css 属性:

$("#treemenu1").css({ "top": "37px", "bottom": "20px" });

回答by ek_ny

$("ul").css("top", "37px");//this should work in all browsers.