html
javascript
$('.moment-btn .add').click(function(){
$('.my-define-moment').append(" ");
});
$('#js-add-li').click(function(){
var momentName = $(this).parent().children('input').val();
$('.my-define-moment').append(""+ momentName +" ");
});
$('body').on('click', '#js-add-li', function() {
$(this).parent('.input-moment-name').remove();
});
点击确定按钮,出现输入框,输入字符后点击确定,添加一个li。如果把结构写进html有用
但是,如果通过append添加的就无法完成第二个项,添加li,而且在两种情况下,点击输入框输入字符时,报错:event is not defined,不点击输入框不报错。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你的my-define-moment 都没有出现在html dom元素中。
button#js-add-li是动态添加的,应该要用on()绑定click事件。