由于某些原因,此代码在IE9中无法工作(无法尝试其他版本的IE)。当试用时,它在Chrome和Firefox中运行良好。当选择下拉项目时,文本框出现消息“未定义”。当选择下拉菜单选项时,需要填充多个文本字段
我无法弄清楚什么是错的,我想这主要是在IE9工作...任何帮助是极大的赞赏..
代码:http://jsfiddle.net/pimvdb/RemPF/1/
谢谢。 中距空空导弹
由于某些原因,此代码在IE9中无法工作(无法尝试其他版本的IE)。当试用时,它在Chrome和Firefox中运行良好。当选择下拉项目时,文本框出现消息“未定义”。当选择下拉菜单选项时,需要填充多个文本字段
我无法弄清楚什么是错的,我想这主要是在IE9工作...任何帮助是极大的赞赏..
代码:http://jsfiddle.net/pimvdb/RemPF/1/
谢谢。 中距空空导弹
}
停止功能printColorAndGroup
。onchange
函数中,您可以通过选择this
。因此,select.options[...]
将是可能的和更清洁。[0]
。修改过的版本:http://jsfiddle.net/pimvdb/RemPF/1/
这是一个文本对象符号:
var colors = { apple: "red",
grape: "purple",
milk: "white",
cheese: "yellow",
chicken: "white",
beef: "red" };
这是标识是如何工作的:
<input type="text" id="food_group" ...>
你可以获取与元素:
document.getElementById('food_group')
这是如何通过选择作品:
<select name="food" onchange="printColorAndGroup(this)">
与以下JavaScript:
function printColorAndGroup(select){
var text = select.options[select.selectedIndex].value;
...
你错过关闭} </script>
标签
function printColorAndGroup(){
var text = document.getElementsByName('food')[0].options[document.getElementsByName('food')[0].selectedIndex].value;
document.getElementsByName('food_group')[0].value = groups[text];
document.getElementsByName('food_color')[0].value = colors[text];
}
非常感谢你..是的,我错过了大括号对不起。..你是非常有益的..再次感谢.. –
哦,顺便说一下,这似乎是不与IE浏览器,它在Chorme ..不知道为什么,可以帮助我呢?我试过在IE 9 .. –
@Raam:不知道,在IE9中为我工作。 – pimvdb