Home  >  Article  >  Web Front-end  >  js method to edit div node name_javascript skills

js method to edit div node name_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:26:05894browse

The example in this article describes the method of editing div node names in js. Share it with everyone for your reference. The specific implementation method is as follows:

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;
}

I hope this article will be helpful to everyone’s JavaScript programming design.

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