if else用法和javascript不一样的,用switch 为何不行呢
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>下拉列表的change事件</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h3>下拉列表的change事件</h3>
<select id="seltest">
<option value="葡萄">葡萄</option>
<option value="苹果">苹果</option>
<option value="荔枝">荔枝</option>
<option value="香焦">香焦</option>
</select>
<script type="text/javascript">
$(function () {
$("select").bind("change", function () {
var $this_val=$(this).val();
switch($this_val)
{
case "香蕉":
$(this).css("background-color","red");
break;
default:
$(this).css("background-color","red");
}
})
});
</script>
</body>
</html>