[英]Clear button Settings on a form
我使用的是表格,想知道是否有人知道可以编辑清除按钮实际清除哪些字段的JavaScript?
即我只希望用户单击表单上的清除按钮后清除选定数量的字段。
input id='FrmReset' type='reset' value='Clear' name='resetButton' onclick='formReset(document.getElementById("Form")); return false;'
我只有以下内容可以清除所有内容
<input id='FrmReset' type='reset' value='Clear' name='resetButton' onclick='formReset(document.getElementById("Form")); return false;' />
假设您有4个这样的字段:
<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事件的普通按钮:
<button onclick="clearNeeded()">Clear only bottom fields</button>
function clearNeeded() {
document.getElementById('i3').value='';
document.getElementById('i4').value='';
}
如您所见-该函数有选择地仅选择特定字段并重置其值。
演示: http : //jsfiddle.net/rdnT3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.