[英]Multiple Conditional Statements in a Javascript function
I haven't used JavaScript for sometime. 我有一段时间没有使用JavaScript了。
I'm trying to get this following script working so if I select "Ireland" in the dropdown, the Ireland select menu appears below. 我正在尝试使以下脚本正常工作,因此,如果在下拉列表中选择“爱尔兰”,则爱尔兰选择菜单将显示在下面。 The same goes for America and Canada.
美国和加拿大也是如此。
http://jsfiddle.net/mcgarriers/DPSe4/ http://jsfiddle.net/mcgarriers/DPSe4/
However it's just not working. 但是,它只是不起作用。 Can anyone take a look and explain why?
谁能看看并解释原因?
I'm sure it's something simple. 我敢肯定这很简单。
Many thanks for any help at all. 非常感谢您的帮助。
Now its working : 现在工作:
http://jsfiddle.net/DPSe4/3/ http://jsfiddle.net/DPSe4/3/
You needed to pass the "SELECT" node to the function , instead of the form. 您需要将“ SELECT”节点传递给函数,而不是表单。
It is because of this keyword. 因为有这个关键字。 Inside of your function it reffers to DOM window object.
在函数内部,它引用DOM窗口对象。 Use
采用
<select onchange='switchStates(this)'>
....
<script>
switchStates(Sender){
alert(Sender.selectedIndex+"-"+Sender.value);
}
</script>
You're passing this.form to the function, but you've not put the parameter into the function parameter list. 您正在将this.form传递给函数,但尚未将参数放入函数参数列表中。 ie:
即:
function switchStates( form ) {
...
}
Also, you're not referencing the form's select object; 另外,您没有引用表单的选择对象; you need
form.dcountry.selectedIndex
您需要
form.dcountry.selectedIndex
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.