append() 方法在被選元素的結尾(在內部)插入指定內容。
如$("p").append(" <b>Hello world!</b>");
appendTo() 方法在被選元素的結尾(在內部)插入指定內容。
如:$("<b>Hello World!</b>").appendTo("p");
prepend() 方法在被選元素的開頭插入內容。
如:$("p").prepend("Some prepended text.");
after() 方法在被選元素之后插入內容。
before() 方法在被選元素之前插入內容。
如$("img").after("Some text after");$("img").before("Some text before");
資料來源網絡:的方式有哪些
在JS中插入短的HTML代碼,可以通過先使用一個函數來包著,你要添加的HTMl代碼,然后在使用innerHTML這個函數提取就行,在你的HTMl中添加一個事件就行,然后調用這個函數就行了,具體的我提供例子給你看下:
<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方法原意為當調用對象或上下文存在trim屬性的話,就調用原來的trim方法,否則就調用replace方法

聲明:本網站尊重并保護知識產權,根據《信息網絡傳播權保護條例》,如果我們轉載的作品侵犯了您的權利,請在一個月內通知我們,我們會及時刪除。
蜀ICP備2020033479號-4 Copyright ? 2016 學習鳥. 頁面生成時間:3.314秒