使用Javascript重置除一个字段以外的表单 [英] Reset a form except one field with Javascript

查看:102
本文介绍了使用Javascript重置除一个字段以外的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我需要重置表单,但我希望一个字段保持不变。

For some reason, I need to reset a form but I want one field to remain unchanged.

以下代码清除所有字段,但我想保留第一个不变。

This following code clears all the fields but I would like to keep the first one unchanged.

<form id="myForm">
    <input id="01" type="text"/>
    <input id="02" type="text"/>
    <input id="03" type="text"/>
    <input id="04" type="text"/>
</form>
<button onclick="document.getElementById('myForm').reset()">Reset</button>

如果可能,我想避免使用jQuery。

If possible, I would like to avoid jQuery.

推荐答案

将其值复制到一个变量中。重置表单。重新将变量重新分配给值。

Copy its value to a variable. Reset the form. Reassign the variable back to the value.

这篇关于使用Javascript重置除一个字段以外的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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