對於我的生活,我無法弄清楚爲什麼JQuery無法在此代碼中找到選擇列表。我試圖訪問在幾個JQuery的測試頁面中選擇元素,它似乎總是不錯,但是這只是沒有做任何事情:JQuery無法查找選擇列表
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function() {
var new_options = ['were filled with rocks', 'smelled like chicken pox', 'belonged to angry green crocs', 'are kept in a mouldy box' ];
/* Remove all options from the select list */
$("#activity_1").empty();
/* Insert the new ones from the array above */
$.each(new_options, function(value) {
$("#activity_1").append($('<option>', {value: 'Testing', text : 'Testing'}));
});
});
</script>
</head>
<body>
<select id='#activity_1'><option value='dud'>This shouldn't be here</option</select>,
</body>
</html>
請檢查您的標記的有效性。看起來'
您的html中也有一個逗號(請參閱select後) –