当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery使用prepend()方法在元素前添加内容用法实例教程

jQuery使用prepend()方法在元素前添加内容用法实例教程

2019年05月17日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery使用prepend()方法在元素前添加内容的用法。分享给大家供大家参考。具体分析如下:

下面的代码可实现在文本前和列表前添加新的元素

<!doctype html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
 $("#btn1").click(function(){
  $("p").prepend("<b>prepended text</b>. ");
 });
 $("#btn2").click(function(){
  $("ol").prepend("<li>prepended item</li>");
 });
});
</script>
</head>
<body>
<p>this is a paragraph.</p>
<p>this is another paragraph.</p>
<ol>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
</ol>
<button id="btn1">prepend text</button>
<button id="btn2">prepend list item</button>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网