我有二维数组,例如var TZa = new Array("Pacific/Wallis;WFT-12", "Pacific/Wallis;WFT-12")
第一个值放置在<select id="stzone"><option></option></select>中,第二个值(在分号之后)放置到<input type="text" id="timezone" >中。
工作正确的旧代码如下:
function SelChng() {
Sel = document.getElementById("stzone");
Inpt = document.getElementById("timezone");
Inpt.disabled = !(Sel.value == "extended");
Inpt.value = TZa[Sel.selectedIndex];
}新代码如下:
$(document).ready(function() {
var input = $("#timezone").attr("disabled", true);
$("#stzone").on("change", function() {
if ($(this).val() == "extended") {
input.attr("disabled", false);
} else {
input.attr("disabled", true);
}
input.val() = TZa[(this).selectedIndex];
});
});并且不根据数组从input type="text"更改值。
拜托,给我点办法来修复我的密码?
发布于 2014-08-01 05:23:59
要使第二段代码像第一段代码一样工作,我认为您的问题在于jQuery:
input.val() = TZa[(this).selectedIndex];看起来应该是:
input.val(TZa[this.selectedIndex]);查看如何使用val()在jQuery上设置值。
发布于 2014-08-01 05:21:09
你说的是“第一价值”和“第二价值”,所以用它?
var TZa = [
{ area: "Pacific", location: "Wallis", wft: -12 },
{ area: "Pacific", location: "Wallis", wft: -12 }
];然后遍历TZa数组:
function buildMyData(data, index) {
// build new HTML elements with data.area, data.location and data.wft
}
TZa.forEach(buildMyData);这不是一个直截了当的答案,但它会让你真正做的事情变得更容易(你的问题很不清楚那是什么),要容易得多。
https://stackoverflow.com/questions/25073265
复制相似问题