单击按钮在HTML插入一行

<button class="create-p">Click Me</button>

<script>

$(".create-p").on("click",function(){   //单击事件

  console.log(1);

  $(this).prepend('<p>插入一行</p>');//在按钮的内部的上方添加一行

  $(this).append('<p>插入一行</p>');//在按钮的内部的下方添加一行

  $(this).before('<p>插入一行</p>');//在元素的前面添加一行

  $(this).after('<p>插入一行</p>');//在元素的后面添加一行    

})

</script>

猜你喜欢

转载自blog.csdn.net/memoryI/article/details/88580238