gpt4 book ai didi

javascript - Firefox javascript错误函数 "undefined"在IE中工作正常

转载 作者:行者123 更新时间:2023-12-02 20:29:35 25 4
gpt4 key购买 nike

我在 Firefox 错误控制台中收到错误“错误:submitSearchForm 未定义”

这是我的该函数的代码

编辑:添加完整代码

   function submitSearchForm(action,iskeyDown) {

var oneEntered = false;

if(iskeyDown == null || iskeyDown == 'undefined'){
copyAndValidate("dobFrom", "searchCriteria.dob", "date");
copyAndValidate("dobTo", "searchCriteria.dobTo", "date");
copyAndValidate("dodFrom", "searchCriteria.dodFrom", "date");
copyAndValidate("dodTo", "searchCriteria.dodTo", "date");
copyAndValidate("searchCriteria.age", "searchCriteria.age", "integer");
}else{
copyAndValidate("dobFrom_date", "searchCriteria.dob", "date");
copyAndValidate("dobTo_date", "searchCriteria.dobTo", "date");
copyAndValidate("dodFrom_date", "searchCriteria.dodFrom", "date");
copyAndValidate("dodTo_date", "searchCriteria.dodTo", "date");
copyAndValidate("searchCriteria.age", "searchCriteria.age", "integer");
}



var elements = document.SearchForm.getElementsByTagName("INPUT");
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element != null && element.getAttribute("group") == 'searchCriteria') {
if (!isEmpty(element.value)) {
oneEntered = true;
break;
}
}
}

if (oneEntered)

{

if (validate(document.SearchForm)) {

document.SearchForm.action.value = action;
document.SearchForm.submit();
}

}


else {
alert("<%= bpt.getValue("CCT_ATLEASTONE_MSG") %>");
}


}

按钮

onclick="<%="submitSearchForm('"+SearchForm.ACTION_SEARCH +"');"%>"

再说一次,在 IE 中一切正常,因此代码是正确的

编辑:VALIDATION.JS validate()

function validate(thisForm) {

window.event.returnValue = false;
formToValidate = thisForm;
var ret = true;
var validationErrors = new Array();

// get the validateable items
// var validateThese = getValidationItems(thisForm.childNodes);
var validateThese = getValidationItems(thisForm);
//printValidationArray(validateThese);

// validate them
for (var i = 0; i < validateThese.length; i++) {
var validationItem = validateThese[i];
var validationError = validateMe(validationItem);
if (validationError != "") {
validationErrors[validationErrors.length] = validationError;
}
}

// check for validation errors
if (validationErrors.length > 0) {
var errors = "";
for (var j = 0; j < validationErrors.length; j++) {
errors += validationErrors[j] + "\n";
}
alert("Validation Errors:\n" + errors);
ret = false;
} else {
ret = true;
}
return ret;
}

最佳答案

window.event(也称为 event)不是 JavaScript 中的标准全局对象。这是 IE 独有的“功能”。

参见this question .

<小时/>

尝试将函数声明更改为:

function submitSearchForm(action, iskeyDown) {
// ...
// { <------------------------------------------------ brace removed
if (validate(document.SearchForm)) {
document.SearchForm.action.value = action;
document.SearchForm.submit();
}
// } <----------------------------------------------- brace removed
}

JavaScript 中大括号的工作方式与 Java 中的大括号不同。根据它们放置的位置,它们具有不同的含义。示例:this question .

我猜测 submitSearchForm 函数声明中的语法错误是问题的根源。

<小时/>

我仍然不确定您发布的代码实际上是浏览器看到的代码,但如果是这样,请尝试以下操作:

function submitSearchForm(action, iskeyDown) {
var oneEntered = false;

if (iskeyDown === null || typeof iskeyDown === 'undefined') {
copyAndValidate("dobFrom", "searchCriteria.dob", "date");
copyAndValidate("dobTo", "searchCriteria.dobTo", "date");
copyAndValidate("dodFrom", "searchCriteria.dodFrom", "date");
copyAndValidate("dodTo", "searchCriteria.dodTo", "date");
copyAndValidate("searchCriteria.age", "searchCriteria.age", "integer");
} else {
copyAndValidate("dobFrom_date", "searchCriteria.dob", "date");
copyAndValidate("dobTo_date", "searchCriteria.dobTo", "date");
copyAndValidate("dodFrom_date", "searchCriteria.dodFrom", "date");
copyAndValidate("dodTo_date", "searchCriteria.dodTo", "date");
copyAndValidate("searchCriteria.age", "searchCriteria.age", "integer");
}

var elements = document.SearchForm.getElementsByTagName("INPUT");
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element !== null && element.getAttribute("group") === 'searchCriteria') {
if (!isEmpty(element.value)) {
oneEntered = true;
break;
}
}
}

if (oneEntered)
{
if (validate(document.SearchForm)) {

document.SearchForm.action.value = action;
document.SearchForm.submit();
}
}

else {
alert('<%= bpt.getValue("CCT_ATLEASTONE_MSG") %>');
}
}

关于javascript - Firefox javascript错误函数 "undefined"在IE中工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4389695/

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