嗨,我正在尝试创建一个按钮来清除 Divs 框中的所有表单字段和数组一个按钮,我将在顶部的下方发布 2 个脚本
,将清除 div,仅底部的一个将清除表单
function clearForms()
{
number=[]
number.splice(0);
var x = document.getElementById("box");
x.innerHTML = "";
x.innerHTML = number.join('<br/>');
}
function clearForms()
{
var x, y, z, type = null;
for (x = 0; x < document.forms.length; x++)
{
for (y = 0; y < document.forms[x].elements.length; y++) {
type = document.forms[x].elements[y].type;
('form='+x+' element='+y+' type='+type);
switch (type)
{
case 'text':
case 'textarea':
case 'password':
//case "hidden":
document.forms[x].elements[y].value = '';
break;
case 'radio':
case 'checkbox':
document.forms[x].elements[y].checked = '';
break;
case 'select-one':
document.forms[x].elements[y].options[0].selected = true;
break;
case 'select-multiple':
for (z = 0; z < document.forms[x].elements[y].options.length; z++)
{
document.forms[x].elements[y].options[z].selected = false;
}
break;
}
// end switch
}
// end for y
}
// end for x
}