当我想重定向时,变量 where 始终是未定义的。但是,例如,我想将该变量放入 alert();
中,它会显示正确的数字。
代码
var where = msg.txt;
window.location = "/page.php?id=".where; //this redirects to /page.php?id=undefined
alert(where); //it show correct number
最佳答案
应该是:
window.location = "/page.php?id=" + where;
你有:
"/page.php?id=".where;
它尝试检索字符串的 where
属性,但尚未定义该属性。
关于javascript变量总是未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13211445/