HTML 表单(通过 PHP 输出)
$retVal .= "<form id= 'importSampleDataForm' name = 'importSampleDataForm' onsubmit = \"return false\" >\n";
// Form content edited out; it contains several dozen checkboxes
$retVal .= sprintf("<input type='button' class='wn_button' onclick='SaveMotorSkills();' value='Import Selected'>\n");
$retVal .= "</form>\n";
JavaScript/Ajax
function SaveMotorSkills() // {{{
{
// {{{ Ajax Header
var httpRequest = CreateHttpRequest();
if (!httpRequest) {
DialogFail('AJAX initialization error. ', 1 );
return false;
} // }}}
var params = '_SaveMotorSkills=1';
for(i=0; i<document.importSampleDataForm.elements.length; i++) // line with error
{
params += "&" + document.importSampleDataForm.elements[i].name +
"=" + document.importSampleDataForm.elements[i].value ;
}
// edit out AJAX setup
httpRequest.send(params);
DialogSave("Saving...");
} // }}}
请参阅 for
循环中的“上面有错误的行”。 JS 控制台说
未捕获类型错误:无法读取未定义的属性“元素”
我已经看了太多这段代码了,我的眼睛已经无法忍受了。还有其他人看到我看不到的东西吗?如果需要,我可以添加更多代码。
最佳答案
尝试
document.getElementById('importSampleDataForm').elements.length
此外,nested forms are not allowed ,所以这也需要解决。
关于javascript - 无法读取未定义的属性 'Elements' - 在 JS 控制台中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19600288/