gpt4 book ai didi

javascript - 在 Web Archive 上加载我的代码,JavaScript 无法正常运行

转载 作者:行者123 更新时间:2023-12-03 06:41:05 26 4
gpt4 key购买 nike

我一直在尝试通过多次查看让我的代码运行良好,比如Web Archive并通过PHProxy 。这是代码:

<select id="mySelect" OnChange="window.location.href=this.value">
<option>Tagged Stuff and Navigation</option>
</select>

<script>
if (window.location.href.substring(0, 9) === "http://th") {
var home_var = "/";
var bio_var = "/tagged/bio";
var ask_var = "/ask";
} else if (window.location.href.substring(0, 9) === "https://p") {
var home_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com";
var bio_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com/tagged/bio";
var ask_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com/ask";
} else if (window.location.href.substring(0, 9) === "https://w") {
var home_var = "blog.tumblr.com";
var bio_var = "blog.tumblr.com/tagged/bio";
var ask_var = "blog.tumblr.com/ask";
}
var select = document.getElementById("mySelect");
var option = document.createElement("option");
var option1 = document.createElement("option");
var option2 = document.createElement("option");

option.text = "Home Page";
option.value = home_var;
select.add(option);

option1.text = "Autobiographys";
option1.value = bio_var;
select.add(option1);

option2.text = "Ask Me Stuff";
option2.value = ask_var;
select.add(option2);
</script>

我的具体问题是,当通过网络文件打开我的页面时,变量从未正确定义,因此所有值都显示为“未定义”。这是网络文件馆的问题吗?或者我可以解决这个问题吗?

最佳答案

window.location.href.substring(0,9) 不包含匹配的字符串。条件未匹配,默认值也未定义,因此该值显示为未定义。

检查

console.log(window.location.href.substring(0, 9));

这是我尝试过的

<select id="mySelect" OnChange="window.location.href=this.value">
<option>Tagged Stuff and Navigation</option>
</select>

<script>
var home_var = "";
var bio_var = "";
var ask_var = "";
// Check your variable
console.log(window.location.href.substring(0, 9));
if (window.location.href.substring(0, 9) === "http://th") {
home_var = "/";
bio_var = "/tagged/bio";
ask_var = "/ask";
} else if (window.location.href.substring(0, 9) === "https://p") {
home_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com";
bio_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com/tagged/bio";
ask_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com/ask";
} else if (window.location.href.substring(0, 9) === "https://w") {
home_var = "blog.tumblr.com";
bio_var = "blog.tumblr.com/tagged/bio";
ask_var = "blog.tumblr.com/ask";
} else {
//Set Default Values
home_var = "default home var";
bio_var = "default home var";
ask_var = "default home var";
}
var select = document.getElementById("mySelect");
var option = document.createElement("option");
var option1 = document.createElement("option");
var option2 = document.createElement("option");

option.text = "Home Page";
option.value = home_var;
select.add(option);

option1.text = "Autobiographys";
option1.value = bio_var;
select.add(option1);

option2.text = "Ask Me Stuff";
option2.value = ask_var;
select.add(option2);
</script>

关于javascript - 在 Web Archive 上加载我的代码,JavaScript 无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37956812/

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