将元素颜色重置为默认样式表颜色(jQuery,JavaScript) [英] Reset element color to default stylesheet color (jQuery, JavaScript)

查看:81
本文介绍了将元素颜色重置为默认样式表颜色(jQuery,JavaScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够将输入字段重置为原始颜色,之后可能会通过javascript更改为其他值。问题是我不想硬编码的值,如果样式表更改。我想使用页面上使用的默认颜色。

I need to be able to reset an input field back to its original color after it has been possibly changed via javascript to a different value. The problem is I do not want to hard code the value in case the stylesheet changes. I would like to use the default color used on the page.

重置颜色像这样好,或者有更好的方法吗?

Is resetting the color like this fine, or is there a better way to do this?

$('#theinput').css('color', '');


推荐答案

没有更好的方法。这是标准的方式。

There's no better way. It's the standard way.

基本上,没有办法从DOM元素的样式属性中删除CSS属性。所以你可以做的是将属性值设置为空,让CSS做它的工作恢复到样式表。

Basically, there's no way to delete a CSS attribute from the style property of DOM elements. So all you can do is set the attribute value to empty and let CSS do its job of reverting back to the stylesheet.

这篇关于将元素颜色重置为默认样式表颜色(jQuery,JavaScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆