บทความนี้อธิบายวิธีการแก้ไขชื่อโหนด Div โดย JS แบ่งปันสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
รหัสโหนด HTML มีดังนี้:
คัดลอกรหัสดังนี้: <div id = "img_1">
<อินพุต type = "image" src = "img/cump.png"> </input>
<div id = "notetxt" type = "text" ondblclick = "changename (this.id);"> 123 </div>
</div>
JS Edit Notetxt Text, ฟังก์ชั่นมีดังนี้:
การคัดลอกรหัสมีดังนี้: ฟังก์ชั่น changename (notetxtid) {
var notetxt = document.getElementById (notetxtid);
notetxt.style.display = "ไม่มี"; //. style.display = "block"
var div = notetxt.parentNode;
if (! document.getElementById ("noteInput")) {
var text = document.createElement ("อินพุต");
text.type = "text";
text.id = "noteInput";
text.style.width = getStyle (notetxt, 'width');
text.style.height = getStyle (notetxt, 'ความสูง');
text.style.margintop = getStyle (notetxt, 'Margintop');
text.style.textalign = getStyle (notetxt, 'textalign');
text.value = notetxt.innerhtml;
Div.AppendChild (ข้อความ);
text.select ();
text.onblur = function () {
notetxt.style.display = "block";
notetxt.innerhtml = text.value;
//text.style.display= "ไม่มี";
Div.RemoveChild (ข้อความ);
-
-
-
// รับสไตล์ในไฟล์ CSS
ฟังก์ชั่น getstyle (obj, attr)
-
if (obj.currentstyle)
-
ส่งคืน obj.currentstyle [attr]; //เช่น
}อื่น{
กลับ getComputedStyle (obj, false) [attr]; // ff
-
-
CSS มีดังนี้:
คัดลอกรหัสดังนี้: .img_1 {
ความกว้าง: 80px;
ความสูง: 70px;
ตำแหน่ง: สัมบูรณ์;
-
.notetext {
ความกว้าง: 80px;
ความสูง: 15px;
TEXT-ALIGN: CENTER;
ระยะขอบด้านบน: 70px;
คำพูด: break-all;
-
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน