我想在我的网页中使用 jQuery。我不想下载它,所以我从 Google 的 CDN 中包含它。
当我运行页面时,jQuery 不工作。
谁能告诉我问题是出在 jQuery 中还是在我的代码中。
这是我的代码。
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
cars=new Array("Mercedes","Volvo","BMW","porche");
phones=new Array('Samsung','Nokia','Iphone');
populateSelect();
$(function() {
$('#cat').change(function(){
populateSelect();
});
});
function populateSelect(){
cat=$('#cat').val();
$('#item').html('');
if(cat=='car'){
cars.forEach(function(t) {
$('#item').append('<option>'+t+'</option>');
});
}
if(cat=='phone'){
phones.forEach(function(t) {
$('#item').append('<option>'+t+'</option>');
});
}
}
</script>
</head>
<body>
<select id="cat">
<option value="car">car</option>
<option value="phone">phone</option>
</select>
<select id="item">
</select>
</body>
</html>