Javascript 我的displayError()函数根本不起作用
我做了一个函数,可以显示错误或删除错误 不幸的是,当我以任何方式使用该函数时,例如Javascript 我的displayError()函数根本不起作用,javascript,jquery,ajax,Javascript,Jquery,Ajax,我做了一个函数,可以显示错误或删除错误 不幸的是,当我以任何方式使用该函数时,例如displayError(true,“test”),它不工作 当我检查html代码以查看是否有任何更改时,没有任何更改 function displayError(display, string, xhr) { $("div#error").fadeOut(300, function() { if(arguments.length == 1 && typeof display
displayError(true,“test”)代码>,它不工作
当我检查html代码以查看是否有任何更改时,没有任何更改
function displayError(display, string, xhr) {
$("div#error").fadeOut(300, function() {
if(arguments.length == 1 && typeof display === "boolean" && display == false) {
//do nothing
} else if(arguments.length == 2 && typeof display === "boolean" && display == true && typeof string == "string") {
$("div#error").html('<b style="color: #ce1919;">(!)</b> '+string).fadeIn(300);
} else if(arguments.length == 3 && typeof display === "boolean" && display == true && typeof string == "string" && typeof xhr === "object") {
$("div#error").html('<b style="color: #ce1919;">('+xhr.status+")</b> "+string).fadeIn(300);
}
});
}
函数显示错误(显示、字符串、xhr){
$(“div#error”).fadeOut(300,function(){
if(arguments.length==1&&typeof display==“boolean”&&display==false){
//无所事事
}else if(arguments.length==2&&typeof display==“boolean”&&display==true&&typeof string==“string”){
$(“div#error”).html(“(!)”+string.fadeIn(300);
}else if(arguments.length==3&&typeof display==“boolean”&&display==true&&typeof string==“string”&&typeof xhr==“object”){
$('div#error').html('('+xhr.status+)”)+string.fadeIn(300);
}
});
}
谁能找出问题所在
use
typeof display === "boolean"
typeof xhr === "object"
希望这有帮助
希望这有帮助
希望这有帮助
希望这有帮助
我发现了控制台日志方法。所以我试着检查我的函数是否被触发,它是否被触发。但是后来我发现arguments数组只是空的,这意味着参数在回调中不可用。因此,我将参数存储在一个变量中,然后在回调中的if语句中使用该变量
像这样:
function displayError(display, string, xhr) {
var args = arguments;
$("div#error").fadeOut(300, function() {
if(args.length == 1 && typeof display === "boolean" && display == false) {
//do nothing
} else if(args.length == 2 && typeof display === "boolean" && display == true && typeof string == "string") {
$("div#error").html('<b style="color: #ce1919;">(!)</b> '+string).fadeIn(300);
} else if(args.length == 3 && typeof display === "boolean" && display == true && typeof string == "string" && typeof xhr === "object") {
$("div#error").html('<b style="color: #ce1919;">('+xhr.status+")</b> "+string).fadeIn(300);
}
});
}
函数显示错误(显示、字符串、xhr){
var args=参数;
$(“div#error”).fadeOut(300,function(){
if(args.length==1&&typeof display==“boolean”&&display==false){
//无所事事
}else if(args.length==2&&typeof display==“boolean”&&display==true&&typeof string==“string”){
$(“div#error”).html(“(!)”+string.fadeIn(300);
}else if(args.length==3&&typeof display==“boolean”&&display==true&&typeof string==“string”&&typeof xhr==“object”){
$('div#error').html('('+xhr.status+)”)+string.fadeIn(300);
}
});
}
我发现了控制台日志方法。所以我试着检查我的函数是否被触发,它是否被触发。但是后来我发现arguments数组只是空的,这意味着参数在回调中不可用。因此,我将参数存储在一个变量中,然后在回调中的if语句中使用该变量
像这样:
function displayError(display, string, xhr) {
var args = arguments;
$("div#error").fadeOut(300, function() {
if(args.length == 1 && typeof display === "boolean" && display == false) {
//do nothing
} else if(args.length == 2 && typeof display === "boolean" && display == true && typeof string == "string") {
$("div#error").html('<b style="color: #ce1919;">(!)</b> '+string).fadeIn(300);
} else if(args.length == 3 && typeof display === "boolean" && display == true && typeof string == "string" && typeof xhr === "object") {
$("div#error").html('<b style="color: #ce1919;">('+xhr.status+")</b> "+string).fadeIn(300);
}
});
}
函数显示错误(显示、字符串、xhr){
var args=参数;
$(“div#error”).fadeOut(300,function(){
if(args.length==1&&typeof display==“boolean”&&display==false){
//无所事事
}else if(args.length==2&&typeof display==“boolean”&&display==true&&typeof string==“string”){
$(“div#error”).html(“(!)”+string.fadeIn(300);
}else if(args.length==3&&typeof display==“boolean”&&display==true&&typeof string==“string”&&typeof xhr==“object”){
$('div#error').html('('+xhr.status+)”)+string.fadeIn(300);
}
});
}
我发现了控制台日志方法。所以我试着检查我的函数是否被触发,它是否被触发。但是后来我发现arguments数组只是空的,这意味着参数在回调中不可用。因此,我将参数存储在一个变量中,然后在回调中的if语句中使用该变量
像这样:
function displayError(display, string, xhr) {
var args = arguments;
$("div#error").fadeOut(300, function() {
if(args.length == 1 && typeof display === "boolean" && display == false) {
//do nothing
} else if(args.length == 2 && typeof display === "boolean" && display == true && typeof string == "string") {
$("div#error").html('<b style="color: #ce1919;">(!)</b> '+string).fadeIn(300);
} else if(args.length == 3 && typeof display === "boolean" && display == true && typeof string == "string" && typeof xhr === "object") {
$("div#error").html('<b style="color: #ce1919;">('+xhr.status+")</b> "+string).fadeIn(300);
}
});
}
函数显示错误(显示、字符串、xhr){
var args=参数;
$(“div#error”).fadeOut(300,function(){
if(args.length==1&&typeof display==“boolean”&&display==false){
//无所事事
}else if(args.length==2&&typeof display==“boolean”&&display==true&&typeof string==“string”){
$(“div#error”).html(“(!)”+string.fadeIn(300);
}else if(args.length==3&&typeof display==“boolean”&&display==true&&typeof string==“string”&&typeof xhr==“object”){
$('div#error').html('('+xhr.status+)”)+string.fadeIn(300);
}
});
}
我发现了控制台日志方法。所以我试着检查我的函数是否被触发,它是否被触发。但是后来我发现arguments数组只是空的,这意味着参数在回调中不可用。因此,我将参数存储在一个变量中,然后在回调中的if语句中使用该变量
像这样:
function displayError(display, string, xhr) {
var args = arguments;
$("div#error").fadeOut(300, function() {
if(args.length == 1 && typeof display === "boolean" && display == false) {
//do nothing
} else if(args.length == 2 && typeof display === "boolean" && display == true && typeof string == "string") {
$("div#error").html('<b style="color: #ce1919;">(!)</b> '+string).fadeIn(300);
} else if(args.length == 3 && typeof display === "boolean" && display == true && typeof string == "string" && typeof xhr === "object") {
$("div#error").html('<b style="color: #ce1919;">('+xhr.status+")</b> "+string).fadeIn(300);
}
});
}
函数显示错误(显示、字符串、xhr){
var args=参数;
$(“div#error”).fadeOut(300,function(){
if(args.length==1&&typeof display==“boolean”&&display==false){
//无所事事
}else if(args.length==2&&typeof display==“boolean”&&display==true&&typeof string==“string”){
$(“div#error”).html(“(!)”+string.fadeIn(300);
}else if(args.length==3&&typeof display==“boolean”&&display==true&&typeof string==“string”&&typeof xhr==“object”){
$('div#error').html('('+xhr.status+)”)+string.fadeIn(300);
}
});
}
谢谢。它帮助我解决了代码中的一些问题。它不是我问题的解决方案,因为该函数仍然不起作用。谢谢。它帮助我解决了代码中的一些问题。它不是我问题的解决方案,因为该函数仍然不起作用。谢谢。它帮助我解决了代码中的一些问题。它不是我问题的解决方案,因为该函数仍然不起作用。谢谢。它帮助我解决了代码中的一些问题。它不是我问题的解决方案,因为该函数仍然不起作用。如果检查$(“div#error”),它会发现什么吗?或者它是一个空数组。可能是您的dom未加载或选择器错误代码>在其工作的函数之外。所以我想我的选择