我想要使用change
事件侦听器更改value
的值。可能吗?下面是我的示例代码:使用onchange更改变量值
<select name="select1" onchange="updatevariable(this.value)">
<option value="2" >2</option>
<option value="15" >15</option>
</select>
<script type="text/javascript">
value = "test";
function updatevariable(data) {
value = data;
}
alert(value); // It should be 2/15
</script>
有什么问题?什么不行? –
在您对选择字段进行任何更改(当您分配'value =“test”;'并定义'updatevariable',而不是*当您*调用updatevariable'时)'执行'alert'。把它放在事件处理程序中。 –
是什么问题。它似乎工作正常http://jsfiddle.net/JmpSU/ –