我有以下代码,我认为它很接近,但我遗漏了一些东西。
var mydropdown = document.getElementById('dropdown');
mydropdown.onchange = function(){
var fullString = this.value;
var mySplitResult = fullString.split(".");\
for(i = 0; i < mySplitResult.length; i++){
document.getElementById('a') + i.value = mySplitResult[i]);
}
}
HTML如下:
<select id="dropdown">
<option value="">None</option>
<option value="1220.2440">1220x2440</option>
<option value="640.480">640x480</option>
</select>
<p>Sheet Size <input id="a0" name="a0" size="10"> X <input id="a1" name="a1" size="10" /></p>
非常感谢任何帮助
答案 0 :(得分:1)
您的代码中有两个错误:
)
。所以更新javascript代码是:
// try to use addEventListener,
// so you can add more than one listeners for the same event
mydropdown.addEventListener("change", function(){
var fullString = this.value;
var mySplitResult = fullString.split(".");
for(i = 0; i < mySplitResult.length; i++){
document.getElementById('a' + i) = mySplitResult[i];
}
});
答案 1 :(得分:0)
你的函数有一些小错误,一个是getElementById函数的参数,另一个是我在评论中提到的。
function(){
var fullString = this.value;
var mySplitResult = fullString.split(".");
for(i = 0; i < mySplitResult.length; i++){
document.getElementById('a' + i).value = mySplitResult[i]; //Here was a ')' which was causing syntax error.
}
}