jquery,如何在按下按钮后删除按钮颜色?
<button style="background-color:lightblue" id="extractv">
<b>
Extract<br>v
</b>
</button>
...
$("#extractv").click(function () {
$("#extractv").removeAttr("style");
});
当有人点击按钮后,我想删除按钮上的背景颜色。我不知道为什么它不起作用。
谢谢
戈登
<button style="background-color:lightblue" id="extractv">
<b>
Extract<br>v
</b>
</button>
...
$("#extractv").click(function () {
$("#extractv").removeAttr("style");
});
After someone clicks on the button, I want to remove the background color on the button. I am not sure why it's not working.
Thanks
Gordon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试使用
try using
这?
This?
我不太确定为什么您发布的代码不起作用,但以下代码可以解决
jsfiddle 版本的问题: http:// /jsfiddle.net/UUxHJ/
正如其他人指出的那样,尽管这里只删除背景颜色比完全删除样式属性更好(更面向未来)。
I'm not exactly sure why the code you posted doesn't work but the following will do the trick
jsfiddle version: http://jsfiddle.net/UUxHJ/
As others have pointed out though it's better (more future-proof) here to only remove the background-color versus completely taking out the style attribute.
http://api.jquery.com/css/
http://api.jquery.com/css/
更好的方法是将颜色分配给一个类,然后使用 jQuery 随意添加和删除该类:
这样,您就可以使用您想要的任何样式功能,而无需更改任何 javascript!
A better way to do this is to assign the color to a class, then use jQuery to add and remove the class at will:
This way, you can work with whatever style features you want, without changing any javascript!