如何使用jQuery重置事件的表单元素(输入,选择,文本区域等) [英] How to reset forms elements (input,select,textarea,etc.) on events using jQuery

查看:78
本文介绍了如何使用jQuery重置事件的表单元素(输入,选择,文本区域等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在单击span之后重置表单元素。例如。

I need to reset forms elements after click span for example.

是否有方法通过jQuery重置from而不选择每个元素并删除属性值。

Is there a method to reset the from by jQuery without select each element and remove the attribute value.

一些没有属性值的元素,如 textarea或radio

Some of the elements not having attribute value like textarea or radio

一些像按钮我不想从中删除它。

And some like button I don't want to remove the value from it.

我想用jQuery来使用它重置其他活动

I want use jQuery to use the reset on other events

代码例如 http://jsfiddle.net/pgNrF/

<input type="button" value="Input Button">
<input type="checkbox">
<input type="hidden">
<textarea></textarea>
<span>Reset</span>


推荐答案

如果你包装那些表单元素,这已经内置了以实际形式:

This is already built in if you wrap those form elements in an actual form:

<form id="myform">  
    <input type="button" value="Input Button">
    <input type="checkbox">
    <input type="file">
    <input type="hidden">
    <input type="image">
    <input type="password">
    <input type="radio">
    <input type="submit">
    <input type="text">
    <select>
        <option>Option1</option>
        <option>Option2</option>
        <option>Option3</option>
    </select>

    <textarea></textarea>
    <button type="button">Button</button> 

    <button type="reset">Reset</span>
</form>

FIDDLE

如果你只需要使用jQuery:

If you just have to use jQuery:

$('span').click(function() {
    $('#myform').get(0).reset();
});

FIDDLE

这篇关于如何使用jQuery重置事件的表单元素(输入,选择,文本区域等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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