以下是代码:
<html>
<head>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#dropdown').on('change', function()
{
alert($("#dropdown").val());
});
});
</script>
<select id="dropdown" name="dropdown">
<option value="1">1</option>
<option value="2">2</option>
</select>
</body>
</html>
您可以在这里尝试实时测试:
答案 0 :(得分:6)
您正在导入过于陈旧的jQuery副本。您的版本早于引入.on()
API。
答案 1 :(得分:0)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#dropdown').change( function()
{
alert($("#dropdown").val());
});
});
</script>
<select id="dropdown" name="dropdown">
<option value="1">1</option>
<option value="2">2</option>
</select>