append() 方法在被選元素的結(jié)尾(在內(nèi)部)插入指定內(nèi)容。
如$("p").append(" <b>Hello world!</b>");
appendTo() 方法在被選元素的結(jié)尾(在內(nèi)部)插入指定內(nèi)容。
如:$("<b>Hello World!</b>").appendTo("p");
prepend() 方法在被選元素的開頭插入內(nèi)容。
如:$("p").prepend("Some prepended text.");
after() 方法在被選元素之后插入內(nèi)容。
before() 方法在被選元素之前插入內(nèi)容。
如$("img").after("Some text after");$("img").before("Some text before");
資料來源網(wǎng)絡(luò):的方式有哪些
在JS中插入短的HTML代碼,可以通過先使用一個函數(shù)來包著,你要添加的HTMl代碼,然后在使用innerHTML這個函數(shù)提取就行,在你的HTMl中添加一個事件就行,然后調(diào)用這個函數(shù)就行了,具體的我提供例子給你看下:
<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原型提供了一個method方法,通過它可以為原型添加新的方法
為String原型添加一個trim方法原意為當調(diào)用對象或上下文存在trim屬性的話,就調(diào)用原來的trim方法,否則就調(diào)用replace方法
聲明:本網(wǎng)站尊重并保護知識產(chǎn)權(quán),根據(jù)《信息網(wǎng)絡(luò)傳播權(quán)保護條例》,如果我們轉(zhuǎn)載的作品侵犯了您的權(quán)利,請在一個月內(nèi)通知我們,我們會及時刪除。
蜀ICP備2020033479號-4 Copyright ? 2016 學習鳥. 頁面生成時間:3.314秒