其中,我試圖在「金額」下拉框中提醒所選值,該值是從1到10的數字列表。生成列表並將其插入到一個div。在下拉列表上使用jquery val()
// generate the amount dropdown list
var dropdown = "<select name=\"amount\">";
for(var i=1; i <= MAX_PRINT; i++) {
dropdown = dropdown + "<option>" + i + "</option>"
}
dropdown = dropdown + "</select>";
jQuery("#" + divId).html("<div>Amount: " + dropdown + "</div></div>");
var amount = 1;
jQuery(document).ready(function() {
amount = jQuery("#amount").val();
alert(amount);
});
我的問題是:爲什麼會產生「未定義」當我提醒了多少?我期待它返回選定的號碼
它提醒'undefined'因爲ID元素'amount'不存在。 –