为什么警报会返回“未定义的”#39;变量值?

时间:2014-10-09 04:58:59

标签: javascript jquery

我有一个功能,可以在单击“+”符号时动态添加输入和下拉框。但是,当下拉列表发生变化时,alert会返回undefined。为什么呢?

jQuery(document).change(".marker-drop-down", function() {       
    alert(jQuery(this).attr("id"));     
});

//functions
function addInputBox() {    
    jQuery("#insert-question-inbox").append('<div id="question-'+i+'-div">
<div id="remove-question-'+i+'" class="ui-icon ui-icon-minus remove-question"></div>
<input class="question-input" type="text" id=question-'+i+' value=question-'+i+' />
<select id="question-'+i+'-drop-down" class="maker-drop-down">
<option>Select</option><option value="multiple-choice">Multiple Choice</option>
<option value="select-all">Select all that apply</option></select><br /></div>');
    i += 1;     
}

1 个答案:

答案 0 :(得分:5)

尝试将其用作

$(document).on("change",".maker-drop-down", function(){        
        alert($(this).attr("id"));     
    });