[JavaScript] jQuery通过prepend()方法在html元素前添加内容 →→→→→进入此内容的聊天室

来自 , 2020-07-07, 写在 JavaScript, 查看 108 次.
URL http://www.code666.cn/view/4559912e
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
  5. </script>
  6. <script>
  7. $(document).ready(function(){
  8.   $("#btn1").click(function(){
  9.     $("p").prepend("<b>Prepended text</b>. ");
  10.   });
  11.   $("#btn2").click(function(){
  12.     $("ol").prepend("<li>Prepended item</li>");
  13.   });
  14. });
  15. </script>
  16. </head>
  17. <body>
  18.  
  19. <p>This is a paragraph.</p>
  20. <p>This is another paragraph.</p>
  21. <ol>
  22. <li>List item 1</li>
  23. <li>List item 2</li>
  24. <li>List item 3</li>
  25. </ol>
  26.  
  27. <button id="btn1">Prepend text</button>
  28. <button id="btn2">Prepend list item</button>
  29.  
  30. </body>
  31. </html>
  32.  
  33. //javascript/8108

回复 "jQuery通过prepend()方法在html元素前添加内容"

这儿你可以回复上面这条便签

captcha