<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input  />
    <input  />
    <input  />
    <input  />

    <ul >

        <li>1</li>
        <li>2</li>

    </ul>
    <script src="jquery.js"></script>
    <script>
        $('#a1').click(function () {
            var v = $('#t1').val();

            var temp = "<li>" + v + "</li>";
            // $('#u1').append(temp);
            $('#u1').prepend(temp);
            // $('#u1').after(temp)
            // $('#u1').before(temp)
        });

        $('#a2').click(function () {
            var index = $('#t1').val();
            //$('#u1 li').eq(index).remove();
            //$('#u1 li').eq(index).empty();
        });
        $('#a3').click(function () {
            var index = $('#t1').val();
            var v = $('#u1 li').eq(index).clone();
            $('#u1').append(v);


            //$('#u1 li').eq(index).remove();
            //$('#u1 li').eq(index).empty();
        })
    </script>
</body>
</html>

  使用on事件与body托管解决动态生成标签触发js脚本不生效的问题

     $(document).on('click','.edit',function(){
$('.c1 , .c2').removeClass('hide')
});

// $("body").delegate(".edit","click", function(){
// $('.c1 , .c2').removeClass('hide')
// });
$("body").delegate(".del","click", function(){
console.log('1231');
$(this).parent().parent().remove()
});

相关文章:

  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-10-06
猜你喜欢
  • 2021-12-15
  • 2021-11-27
  • 2021-12-07
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
相关资源
相似解决方案