在当前li后添加新的li,不能执行已设定的方法?

具体如图:

http://img3.mukewang.com/5a9fbcbf00013fee11790264.jpg

http://img1.mukewang.com/5a9fbc9e0001af1a03580098.jpg

http://img.mukewang.com/5a9fbd5f0001ec5e05160118.jpg

具体代码如下:


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<style ></style>

</head>

<body>

<ul >

<li>1:<input type="text" /><button type="button" class="add">增加</button><button type="button" class="del">删除</button></li>

<li>2:<input type="text" /><button type="button" class="add">增加</button><button type="button" class="del">删除</button></li>

</ul>

<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js" ></script>

<script>

$(function(){

$('.add').click(function(){

console.log('dian');

$(this).parent('li').append('<li><input type="text" /><button type="button" class="add">增加</button><button type="button" class="del">删除</button></li>')

})

$('.del').click(function(){

$(this).parent('li').remove();

})

})

</script>

</body>

</html>


Zoe_z
浏览 907回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP