javascript变量总是未定义

标签 javascript variables redirect

当我想重定向时,变量 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/

相关文章:

javascript - HTML : load thumbnail image and full image faster

javascript - 使用动态日期格式验证日期字符串的最佳方法

javascript - Html5 canvas 和 javascript document.getElementById() 返回 null

variables - 解压变量中的字符串

javascript - 为什么我的 react 变量不会在 DOM 上呈现?

variables - Devops YAML - 使用表达式设置构建名称

javascript - 将 Flask 变量直接传递给 vue 的最佳方式是什么?

javascript - 使用重定向来启动应用程序并仍保留在 ASP.NET 中的同一页面中

.htaccess - 多个域名到一个网站

wordpress - 虽然301网站从.de重定向到.com,谷歌索引.de网站