在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ HTML/ 添加HTML元素
jQuery UI Tab 示例(一)
jQuery UI Datepicker 示例(四)
jQuery UI 示例
jQuery UI Slider 示例(二)
jQuery UI Dialog 示例(一)
HTML Get
動畫效果
終止動畫
回調(diào)函數(shù)
方法鏈
jQuery UI Button 示例(一)
jQuery UI Autocomplete 示例(三)
jQuery UI Autocomplete 示例(二)
設(shè)置或取得元素的 CSS class
jQuery UI 概述
基本語法
jQuery UI Datepicker 示例(一)
jQuery UI Autocomplete 示例(一)
jQuery UI Spiner 示例
jQuery UI Tab 示例(二)
淡入淡出效果
顯示/隱藏內(nèi)容
HTML Set
jQuery UI Tooltip 示例
jQuery UI Slider 示例(一)
讀寫 HTML 元素的 css 屬性
jQuery UI Datepicker 示例(二)
添加HTML元素
操作 HTML 元素的大小
jQuery UI Datepicker 示例(五)
滑動效果
jQuery UI Dialog 示例(二)
jQuery UI Menu 示例
jQuery UI 基本工作過程
jQuery UI Button 示例(二)
jQuery UI Dialog 示例(三)
jQuery UI Datepicker 示例(三)
Selectors
jQuery UI Progressbar 示例
Events
jQuery UI Accordion 示例
刪除HTML元素

添加HTML元素

使用 jQuery 可以方便的添加新的 HTML 元素。

下面的方法用于添加 HTML 元素:

  • append() – 在指定的元素的尾部添加一個新內(nèi)容。
  • prepend() -在指定的元素里前部添加新內(nèi)容。
  • after() – 在指定元素前添加新內(nèi)容
  • before() -在指定元素的后面添加新內(nèi)容。

乍一看 append,prepend 和 after,before 似乎功能一樣,但 append,prepend 指在選中的元素本身(內(nèi)部)的前面和后面,而 after,before 指在選擇中的元素的前面和后面。

可以參考下面的 append 例子:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>JQuery Demo</title>
    <script src="scripts/jquery-1.9.1.js"></script>
    <script>
        $(document).ready(function () {
            $("#btn1").click(function () {
                $("p").append(" <b>Appended text</b>.");
            });

            $("#btn2").click(function () {
                $("ol").append("<li>Appended 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">Append text</button>
    <button id="btn2">Append list items</button>
</body>
</html>

http://wiki.jikexueyuan.com/project/jquery-tutorial/images/6.png" alt="" />

prepend 示例:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>JQuery Demo</title>
    <script src="scripts/jquery-1.9.1.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>

http://wiki.jikexueyuan.com/project/jquery-tutorial/images/7.png" alt="" />

append(),prepend()支持同時插入多個元素,下面的例子添加三個使用不同方法創(chuàng)建的新元素:

function appendText()
 {
 // Create element with HTML
 var txt1="<p>Text.</p>";
// Create with jQuery
 var txt2=$("<p></p>").text("Text.");
 // Create with DOM
 var txt3=document.createElement("p");
 txt3.innerHTML="Text.";
 // Append the new elements
 $("p").append(txt1,txt2,txt3);
 }

下面的例子使用 after,before 在指定的元素前后面添加新內(nèi)容:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>JQuery Demo</title>
    <script src="scripts/jquery-1.9.1.js"></script>
    <script>
        $(document).ready(function () {
            $("#btn1").click(function () {
                $("img").before("<b>Before</b>");
            });

            $("#btn2").click(function () {
                $("img").after("<i>After</i>");
            });
        });
    </script>
</head>

<body>
    <img src="/images/guidebee.png"
        alt="guidebee" width="120" height="125">
    <br>
    <br>
    <button id="btn1">Insert before</button>
    <button id="btn2">Insert after</button>
</body>
</html>

http://wiki.jikexueyuan.com/project/jquery-tutorial/images/8.png" alt="" />

同樣 after,before 也支持同時插入多個元素:

function afterText()
 {
  // Create element with HTML 
 var txt1="<b>I </b>";   
// Create with jQuery 
 var txt2=$("<i></i>").text("love ");   
// Create with DOM 
 var txt3=document.createElement("big");  
 txt3.innerHTML="jQuery!";
  // Insert new elements after img
 $("img").after(txt1,txt2,txt3);         
 }