我生成动态表单的javascript代码如下:
function showFormC(){
field = document.getElementById('hideForm');
button = document.getElementById('toggle');
if(formcShowed == false){
field.innerHTML = "";
formcShowed = true;
button.value = 'Hide form c';
}
else {
field.innerHTML = "";
formcShowed = false;
button.value = 'Show form c';
}
}
上述代码的意图是当点击按钮时,如果表单已经显示就隐藏它,如果隐藏就显示它,其中 formcShowed 是一个全局变量。
我的 validate 函数如下:
function validate(form){
if(form === document.form_a){
... ...
}
else if(form === document.forms['form_b']){
... ...
}
else if(form === document.form_c){
sexvalue = form.sex.value;
if(sexvalue == null || sexvalue == ""){
alert('sex can not be empty!');
form.sex.focus();
return false;
}
return true;
}
}
对于静态生成的form_a和form_b,validate的功能可以正确执行,但对form_c,根本没反应。
我在进入validate函数时,就用 alert(form.name); 显示表单名字,可是点击form_c的提交按钮时,连表单名字也不显示。
我还试着用 getElementId 来引用动态表单中的对象,也没有反应。
请教:动态表单中的对象如何引用呢?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
欢迎选择我的课程,让我们一起见证您的进步~~