【发布时间】:2012-02-20 19:49:58
【问题描述】:
在我的下拉列表中,我对其进行了设置,因此 onchange 应该调用 checkval 并传入元素的 id。我刚开始使用非常基本的登录,但甚至无法显示警报。我做错了什么?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script>
function checkval(id){
if($('#' + id).val == "Other")
{
alert("You Selected Other");
//other logic will go here
}
}
</script>
</head>
<body>
<select name="items1[]" id="items1[]" onchange="checkval(id);">
<option selected value="">Select One</option>
<option value="one">One</option>
<option value="Other">Other</option>
</select>
<select name="items2[]" id="items2[]" onchange="checkval(id);">
<option selected value="">Select One</option>
<option value="one">One</option>
<option value="Other">Other</option>
</select>
</body>
</html>
【问题讨论】:
标签: jquery html drop-down-menu