<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>prepend</title> <script src="https://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script> <script> // 参考:https://www.w3school.com.cn/jquery/jquery_dom_add.asp // jQuery prepend() 方法在被选元素的开头插入内容。 // prepend可以接收多个参数,如下: // $("body").prepend(txt1,txt2,txt3); $(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">添加文本</button> <button id="btn2">添加列表项</button> </body> </html>
jquery prepend.html
最新推荐文章于 2021-09-28 17:20:52 发布