javascript令人兴奋的行为
我有这组函数,但它拒绝运行javascript令人兴奋的行为,javascript,if-statement,Javascript,If Statement,我有这组函数,但它拒绝运行 alert('Ok I reach in if 1') 或 尽管如此,我没有html或javascript错误 if输出“baza”前的警报(res[3]) if输出“字符串”之前的警报(类型res[3]) function ataseazaPoza(id, poza) { tip = ''; if (id.search("dragzonesortpic") == 0) { tip = 'sort'; } else { tip = 'b
alert('Ok I reach in if 1')
或
尽管如此,我没有html或javascript错误
if输出“baza”前的警报(res[3])
if输出“字符串”之前的警报(类型res[3])
function ataseazaPoza(id, poza) {
tip = '';
if (id.search("dragzonesortpic") == 0) {
tip = 'sort';
} else {
tip = 'baza';
}
http.open('get', 'produse_ataseazaPoza.php?id=' + id + '&image=' + poza + '&tip=' + tip + '&nocache=' + Math.random());
http.onreadystatechange = ataseazaPozaReply;
http.send(null);
}
function ataseazaPozaReply() {
if (http.readyState == 4) {
var response = http.responseText;
res = response.split(";");
if (res[0] == 'er') {
alert('Eroare: ' + res[1] + ' ' + res[2]);
} else {
keys = res[2].split("-");
alert(res[3]);
if (res[3] == 'baza') {
alert('Ok I reach in if 1');
elemRo = document.getElementById('rowuv' + res[1]).style.backgroundColor = 'transparent';
elemOv = document.getElementById('dragzoneuv' + res[1]);
imgurl = "url('../prod_imagini/" + keys[0] + "/" + keys[0] + "/" + res[2] + "')";
elemOv.style.backgroundImage = imgurl;
}
if (res[3] == 'sort') {
alert('Ok I reach in if 2');
randPlus = parseInt(res[1]) + 1;
elemRo = document.getElementById('sortHoverDrop' + res[1]).style.backgroundColor = 'transparent';
elemOv = document.getElementById('dragzonesortpic' + res[1]);
imgurl = "url('../prod_imagini/" + keys[0] + "/" + keys[0] + "/" + res[2] + "')";
document.getElementById('pozaHiddenSort' + res[1]).value = imgurl;
elemOv.style.backgroundImage = imgurl;
}
}
}
}
为什么不输入呢?您的字符串末尾很可能有一些空格。您可以使用删除多余的空白
var with whitespace='baza';
log(with whitespace+'==“baza”',with whitespace==“baza”);
var withoutWhitespace=withWhitespace.trim();
log(without-hitespace+'==“baza”',without-hitespace==“baza”)代码>字符串的末尾很可能有一些空格。您可以使用删除多余的空白
var with whitespace='baza';
log(with whitespace+'==“baza”',with whitespace==“baza”);
var withoutWhitespace=withWhitespace.trim();
log(without-hitespace+'==“baza”',without-hitespace==“baza”)
有时,无论出于何种原因,控制台中都不会显示错误,因此您必须尝试捕获并警告消息。请使用console.log()
而不是alert()
,因此,您可以看到字符串中的所有字符。有时,无论出于何种原因,控制台中都不会显示错误,您必须将错误放入try中。捕获并警告消息。使用console.log()
而不是alert()
,这样您就可以看到字符串中的所有字符。您真是个天才!这就是问题所在,我有5行空行。。。现在不要从何处开始(php输出正常)。我用.substring(0,4)删除它们,而string将始终有4个字符。你真是个天才!这就是问题所在,我有5行空行。。。现在不要从何处开始(php输出正常)。我用.substring(0,4)删除它们,而string将始终有4个字符。
function ataseazaPoza(id, poza) {
tip = '';
if (id.search("dragzonesortpic") == 0) {
tip = 'sort';
} else {
tip = 'baza';
}
http.open('get', 'produse_ataseazaPoza.php?id=' + id + '&image=' + poza + '&tip=' + tip + '&nocache=' + Math.random());
http.onreadystatechange = ataseazaPozaReply;
http.send(null);
}
function ataseazaPozaReply() {
if (http.readyState == 4) {
var response = http.responseText;
res = response.split(";");
if (res[0] == 'er') {
alert('Eroare: ' + res[1] + ' ' + res[2]);
} else {
keys = res[2].split("-");
alert(res[3]);
if (res[3] == 'baza') {
alert('Ok I reach in if 1');
elemRo = document.getElementById('rowuv' + res[1]).style.backgroundColor = 'transparent';
elemOv = document.getElementById('dragzoneuv' + res[1]);
imgurl = "url('../prod_imagini/" + keys[0] + "/" + keys[0] + "/" + res[2] + "')";
elemOv.style.backgroundImage = imgurl;
}
if (res[3] == 'sort') {
alert('Ok I reach in if 2');
randPlus = parseInt(res[1]) + 1;
elemRo = document.getElementById('sortHoverDrop' + res[1]).style.backgroundColor = 'transparent';
elemOv = document.getElementById('dragzonesortpic' + res[1]);
imgurl = "url('../prod_imagini/" + keys[0] + "/" + keys[0] + "/" + res[2] + "')";
document.getElementById('pozaHiddenSort' + res[1]).value = imgurl;
elemOv.style.backgroundImage = imgurl;
}
}
}
}