gpt4 book ai didi

javascript - 无法读取未定义的属性 'Elements' - 在 JS 控制台中

转载 作者:行者123 更新时间:2023-11-28 15:53:45 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com