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

Javascript implements node (div) name editing_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:25:591162browse

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.

Statement:
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