append() 方法在被選元素的結尾(在內部)插入指定內容。
如$("p").append(" <b>Hello world!</b>");
appendTo() 方法在被選元素的結尾(在內部)插入指定內容。
如:$("<b>Hello World!</b>").appendTo("p");
prepend() 方法在被選元素的開(kāi)頭插入內容。
如:$("p").prepend("Some prepended text.");
after() 方法在被選元素之后插入內容。
before() 方法在被選元素之前插入內容。
如$("img").after("Some text after");$("img").before("Some text before");
資料來(lái)源網(wǎng)絡(luò ):的方式有哪些
在JS中插入短的HTML代碼,可以通過(guò)先使用一個(gè)函數來(lái)包著(zhù),你要添加的HTMl代碼,然后在使用innerHTML這個(gè)函數提取就行,在你的HTMl中添加一個(gè)事件就行,然后調用這個(gè)函數就行了,具體的我提供例子給你看下:
<html>
<head>
<script>
function insert(){
var insertText = "<table><tr><td>any thing</td></tr></table>";
document.getElementById("insert").innerHTML(insertText);
}
</script>
</head>
<body>
<button onclick="insert()">Insert</button>
<div id="insert"></div>
</body>
</html>
方法一:Script Dom Element
(function(){
var scriptEle = document.createElement("script");
scriptEle.type = "text/javasctipt";
scriptEle.async = true;
scriptEle.src = ">
Function.prototype.method=function(name,func){
this.prototype[name]=func;
return this;
}
String.method('trim',function(){
if('trim' in this){
return this.trim);
}else{
return this.replace(/^\s+|\s+$/g,'');
}
});
上面的代碼為Function原型提供了一個(gè)method方法,通過(guò)它可以為原型添加新的方法
為String原型添加一個(gè)trim方法原意為當調用對象或上下文存在trim屬性的話(huà),就調用原來(lái)的trim方法,否則就調用replace方法
聲明:本網(wǎng)站尊重并保護知識產(chǎn)權,根據《信息網(wǎng)絡(luò )傳播權保護條例》,如果我們轉載的作品侵犯了您的權利,請在一個(gè)月內通知我們,我們會(huì )及時(shí)刪除。
蜀ICP備2020033479號-4 Copyright ? 2016 學(xué)習?shū)B(niǎo). 頁(yè)面生成時(shí)間:3.314秒