清除表单上的按钮设置 [英] Clear button Settings on a form

查看:285
本文介绍了清除表单上的按钮设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用表单,并想知道是否有人知道一些可以编辑清除按钮实际清除的字段的JavaScript?

I am using a form and was wondering if anyone knows some JavaScript that can edit what fields the clear button actually clears?

即使用户点击表单上的清除按钮,我只希望清除一定数量的字段。

i.e i only want a select number of fields to be cleared once the user hits the clear button on the form.

input id='FrmReset' type='reset' value='Clear' name='resetButton' onclick='formReset(document.getElementById("Form")); return false;'  

我只有以下几项清除了所有内容

I just have the following which clears everything

<input id='FrmReset' type='reset' value='Clear' name='resetButton' onclick='formReset(document.getElementById("Form")); return false;' />


推荐答案

假设您有4个字段, p>

Let's say you have 4 fields like this:

<input type="text" value="don't clear this" id="i1" />
<input type="text" value="don't clear this" id="i2" />
<br/>
<input type="text" value="clear this" id="i3" />
<input type="text" value="clear this" id="i4" />

您只需要清除底部的内容2.添加一个带有onclick事件的普通按钮:

And you need to clear only bottom 2. Add a normal button with onclick event:

<button onclick="clearNeeded()">Clear only bottom fields</button>

function clearNeeded() {
    document.getElementById('i3').value='';
    document.getElementById('i4').value='';
}

正如您所看到的 - 该函数有选择地只选择特定的字段并重置其值。

As you can see - the function selectively picks only specific fields and resets their values.

演示: http://jsfiddle.net/rdnT3/

这篇关于清除表单上的按钮设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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