1 回答
TA贡献1828条经验 获得超3个赞
stores版本 2 中的变量将覆盖初始范围变量。正如在您的示例中所观察到的,"test3"并且"test4"未使用,因此将它们放在stores对象中毫无意义。
示例"T"中的大小写也与值的大小写不匹配<select>
也snippetMobile从未定义,我假设您指的Adress是显示选定的选项,因此我进行了这些更改。
var Store = document.getElementById("Store"),
Adress = document.getElementById("Adress"),
stores = {
noSelection: "",
test1: "Test1",
test2: "Test2",
test3: "Test3",
test4: "Test4",
}
Store.onchange = function() {
Adress.innerHTML = stores[this.value];
}
var Gas = document.getElementById("Gas"),
Number = document.getElementById("Number");
Gas.onchange = function() {
Number.innerHTML = stores[this.value];
}
<select id="Store">
<option value="noSelection">Snippet</option>
<option value="test1">Test1</option>
<option value="test2">Test2</option>
</select>
<span id="Adress"></span>
<select id="Gas">
<option value="noSelection">Snippet</option>
<option value="test1">Test1</option>
<option value="test2">Test2</option>
</select>
<span id="Number"></span>
添加回答
举报