如何使用javascript更改类名 [英] How do I change a class name using javascript

查看:92
本文介绍了如何使用javascript更改类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入:

I have a input:

<form id="integer" role="form" name="_form">
<div class="form-group">
                        <label>Amount</label>
                        <input type="number" name="Amount" class="form-control" placeholder="Enter amount">
                    </div>
</form>





使用javascript函数如何更改



Using a javascript function how can i change the

class="form-control"



例如当有人点击提交时?


For example when someone clicks submit?

推荐答案

检查出来: http://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript [ ^ ]


除了解决方案2:



类只是DOM的一部分,可以完全由JavaScript控制。执行此类操作的一种简单方法是使用jQuery。请参阅:

http://api.jquery.com/addClass/ [ ^ ],

http://api.jquery.com/removeClass/ [ ^ ],

http://api.jquery。 com / toggleClass / [ ^ ],

http://api.jquery.com/category/css [ ^ ]。



如果你需要学习jQuery(强烈推荐),请参阅:

http://en.wikipedia.org/wiki/ JQuery [ ^ ],

http://jquery.com [ ^ ],

http: //learn.jquery.com [ ^ ],
http://learn.jquery.com/using-jquery-core [ ^ ],

http://learn.jquery.com/about-jquery/how-jquery-works [<一个href =http://learn.jquery.com/about-jquery/how-jquery-works/target =_ blanktitle =New Window> ^ ](从这里开始)。



-SA
In addition to Solution 2:

Class is just a part of DOM, which can be fully controlled by JavaScript. One simple way of doing such things is using jQuery. Please see:
http://api.jquery.com/addClass/[^],
http://api.jquery.com/removeClass/[^],
http://api.jquery.com/toggleClass/[^],
http://api.jquery.com/category/css[^].

If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com[^],
http://learn.jquery.com[^],
http://learn.jquery.com/using-jquery-core[^],
http://learn.jquery.com/about-jquery/how-jquery-works[^] (start from here).

—SA


这篇关于如何使用javascript更改类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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