如何删除表单内所有输入字段中的类 - jquery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8768653/
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-27 11:00:35  来源:igfitidea点击:

How to remove class in all input field inside a form - jquery

jquery

提问by Fero

While i click the submit button the form will look like below with error messages:

当我单击提交按钮时,表单将如下所示,并带有错误消息:

My Problem is when i click on clear link i need to remove the error class in input fieldsand clear the values in messages-inlineclass.

我的问题是当我点击清除链接时,我需要remove the error class in input fields清除messages-inline课堂中的值。

How can i do that using jquery.

我如何使用 jquery 做到这一点。

Note: there may be many fields such like password, confirm password etc... So the concept should be dynamic.

注意:可能有很多字段,如密码、确认密码等......所以这个概念应该是动态的。

<form id="user-login" method="post" accept-charset="UTF-8" action="/user/register?destination=node%2F1" novalidate="novalidate">
    <div id="edit-name-wrapper" class="form-item">
        <label for="edit-name">
            <span title="This field is required." class="form-required">*</span>
            E-mail: 
        </label>
        <input type="text" class="form-text required error" tabindex="1" value="" size="60" id="edit-name" name="name" maxlength="60">
    </div>    
    <div class="messages error messages-inline">E-mail field is required.</div>

    <input type="submit" class="form-submit" tabindex="4" value="Log in" id="edit-submit" name="op">
    </div>
</form>

回答by Pavan

You can try this

你可以试试这个

$('input').removeClass('error');
$('.messages-inline').text('');