<script>
function options(){
alert("asdfasdf");
}
</script>
<select type="selectbox" name="crPaymentOption" id ="crPaymentOption"onchange="options()"/>
<option selected="" value="--">--</option>
<option value="Check">Check</option>
<option value="Credit Card">Credit Card</option>
<option value="Cash">Cash</option>
</select>
当我更改选择下拉列表的选项时,警报未触发。谁能帮帮我呢?
答案 0 :(得分:6)
更改方法名称,并在onchange属性前留一个空格:
<script>
function optionsAlert(){
alert("asdfasdf");
}
</script>
<select name="crPaymentOption" id="crPaymentOption" onchange="optionsAlert()"/>
<option selected="" value="--">--</option>
<option value="Check">Check</option>
<option value="Credit Card">Credit Card</option>
<option value="Cash">Cash</option>
</select>
答案 1 :(得分:3)
它不喜欢功能名称 - 将其更改为其他名称,例如changeOptions,并使用它。以下是适用于我的代码版本:
<html>
<body>
<script> function changeOptions(){ alert("asdfasdf"); }</script>
<select type="selectbox" name="crPaymentOption" id="crPaymentOption" onchange="changeOptions()" />
<option selected="" value="--">--</option>
<option value="Check">Check</option>
<option value="Credit Card">Credit Card</option>
<option value="Cash">Cash</option>
</select>
</body>
</html>