jQuery 文檔操作 append() 方法
jQuery 文檔操作 append() 方法
append() 方法在被選元素的結(jié)尾(仍然在內(nèi)部)插入指定內(nèi)容。
提示:append() 和 appendTo() 方法執(zhí)行的任務(wù)相同。不同之處在于:內(nèi)容的位置和選擇器。
1. 語(yǔ)法
$(selector).append(content)
參數(shù) | 描述 |
---|---|
content | 必需。規(guī)定要插入的內(nèi)容(可包含 HTML 標(biāo)簽)。 |
2. 使用函數(shù)來(lái)附加內(nèi)容
使用函數(shù)在指定元素的結(jié)尾插入內(nèi)容。
語(yǔ)法
$(selector).append(function(index,html))
參數(shù) | 描述 |
---|---|
function(index,html) |
必需。規(guī)定返回待插入內(nèi)容的函數(shù)。
|
3. 范例
在每個(gè) p 元素結(jié)尾插入內(nèi)容:
$("button").click(function(){ $("p").append(" <b>Hello world!</b>"); });
相關(guān)文章
- jQuery 效果 隱藏和顯示
- jQuery 效果 淡入淡出
- jQuery 效果 滑動(dòng)
- jQuery 效果 動(dòng)畫
- jQuery 獲得內(nèi)容和屬性
- jQuery 獲取并設(shè)置 CSS 類
- jQuery 尺寸
- jQuery 遍歷 后代
- jQuery 參考手冊(cè) 選擇器
- jQuery 參考手冊(cè) 遍歷
- jQuery 參考手冊(cè) 核心
- jQuery 事件 click() 方法
- jQuery 事件 delegate() 方法
- jQuery 事件 preventDefault() 方法
- jQuery 事件 which 屬性
- jQuery 事件 keyup() 方法
- jQuery 事件 mouseover() 方法
- jQuery 事件 one() 方法
- jQuery 事件 toggle() 方法
- jQuery 事件 unbind() 方法