我在尝试在我的脚本上触发事件(警报)时遇到问题。这是html:
<div class="dynamic-form">
<form>
<div class="inputs"></div>
<a href="#" id="add">ADD</a>
<input name="submit" type="button" class="submit" value="Submit">
</form>
</div>
和 JS:
$(document).ready(function(){
var i = 1;
$('#add').click(function() {
$('<div id="d' + i + '" class="fielddiv"><input type="text" class="field" name="dynamic[]" value="' + i + '" /><a href="#" id="remove_question">Cancella</a><hr></div>').fadeIn('slow').appendTo('.inputs');
i++;
});
$('#remove_question').on("click", function(event) {
alert('dsfsfd');
//$('#d' + $this.attr('todel')).remove();
});
// here's our click function for when the forms submitted
$('.submit').click(function(){
var answers = [];
$.each($('.field'), function() {
answers.push($(this).val());
});
if(answers.length == 0) {
answers = "none";
}
alert(answers);
return false;
});
});
点击功能上的删除问题应该触发警报但没有做任何事情,甚至没有错误,我做错了什么?这也是一个jsfiddle。