JS把內(nèi)容動態(tài)插入到DIV的實現(xiàn)方法
來源:易賢網(wǎng) 閱讀:1262 次 日期:2016-07-26 15:06:22
溫馨提示:易賢網(wǎng)小編為您整理了“JS把內(nèi)容動態(tài)插入到DIV的實現(xiàn)方法”,方便廣大網(wǎng)友查閱!

下面小編就為大家?guī)硪黄狫S把內(nèi)容動態(tài)插入到DIV的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>

 <meta http-equiv="content-type" content="text/html; charset=utf-8" />

 <title>Testing</title>

</head>

<script type="text/javascript" src="example.js">

</script>

<body>

<div id="testdiv">

</div>

</body>

</html>

example.js 文件內(nèi)容:

window.onload = function() {

 var testdiv = document.getElementById("testdiv");

 testdiv.innerHTML="<p>I inserted <em>this</em> content.</p>";

}

另一段代碼:

window.onload = function() {

 var para = document.createElement("p");

 var txt1 = document.createTextNode("I inserted ");

 var emphasis = document.createElement("em");

 var txt2 = document.createTextNode("this");

 var txt3 = document.createTextNode(" content.");

 para.appendChild(txt1);

 emphasis.appendChild(txt2);

 para.appendChild(emphasis);

 para.appendChild(txt3);

 var testdiv = document.getElementById("testdiv");

 testdiv.appendChild(para);

}

這與在DIV內(nèi)動態(tài)載入另一個頁面非常相似!

以上這篇JS把內(nèi)容動態(tài)插入到DIV的實現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:JS把內(nèi)容動態(tài)插入到DIV的實現(xiàn)方法

2026國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)