บทความนี้อธิบายวิธีการเพิ่มเนื้อหาโหนดลงในรูปแบบแบบไดนามิก แบ่งปันสำหรับการอ้างอิงของคุณ รายละเอียดมีดังนี้:
1. รหัส
คัดลอกรหัสดังนี้: <! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<title> เพิ่มโหนด </title>
<script type = "text/javascript">
ฟังก์ชั่น newpicture () {
var picElement = document.createElement ("IMG");
picelement.src = "images/success.jpg";
picelement.width = 100;
picelement.height = 100;
document.body.appendchild (picelement);
-
ฟังก์ชั่น newNode () {
var olelement = document.getElementById ('คำตอบ');
var lielement = document.createelement ('li');
var inputelement = document.createElement ('อินพุต');
inputelement.type = "text";
inputelement.name = "คำตอบ";
lielement.AppendChild (Inputelement);
Olelement.AppendChild (lielement);
-
</script>
</head>
<body>
<div>
<input type = "button" name = "button" value = "เพิ่มรูปภาพ" onclick = "JavaScript: newPicture ();"/>
<input type = "button" name = "button" value = "เพิ่มตัวเลือก" onclick = "JavaScript: newNode ();" /> <br />
<ol id = "คำตอบ">
<li> <input type = "text" name = "answer" /> </li>
</ol>
</div>
</body>
</html>
2. การเรนเดอร์โปรแกรม:
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน