Home > Web Front-end > JS Tutorial > Javascript implements node (div) name editing_javascript skills

Javascript implements node (div) name editing_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:25:59
Original
1206 people have browsed it

The node html code is as follows:

Copy code The code is as follows:



123


js edit noteTxt text, the function is as follows:

Copy code The code is as follows:

Function changeName(noteTxtId){
        var noteTxt = document.getElementById(noteTxtId);
          noteTxt.style.display= "none";//.style.display= "block"
        var div = noteTxt.parentNode;
If(!document.getElementById("noteInput")){
            var text=document.createElement("input");
               text.type="text";
               text.id="noteInput";
                text.style.width=getStyle(noteTxt,'width');
                 text.style.height=getStyle(noteTxt,'height');
                text.style.marginTop=getStyle(noteTxt,'marginTop');
               text.style.textAlign=getStyle(noteTxt,'textAlign');
               text.value=noteTxt.innerHTML;
            div.appendChild(text);
               text.select();
               text.onblur=function(){
                  noteTxt.style.display= "block";
                   noteTxt.innerHTML=text.value;
                       //text.style.display= "none";
              div.removeChild(text);
}
}
}
//Get the style in the css file
Function getStyle(obj, attr)
{
If(obj.currentStyle)
            {
           return obj.currentStyle[attr]; //IE
                                                                                                                return getComputedStyle(obj,false)[attr]; //FF
}
}

css is as follows:

Copy code The code is as follows:
.img_1 {
Width: 80px;
height:70px;
Position:absolute;
}
.noteText {
Width:80px;
height:15px;
Text-align:center;
Margin-top:70px;
Word-break:break-all;
}


The code is very simple, so I won’t explain it here. Friends can play it freely and use it in their own projects.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template