其中,我试图在“金额”下拉框中提醒所选值,该值是从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'不存在。 –