JavaScript implementation node (DIV) name editing _javascript tips

Source: Internet
Author: User

The node HTML code is as follows:

Copy Code code as follows:

<div class= "img_1" id= "img_1" >
<input type= "image" class= "img_1" src= "Img/cump.png" ></input>
<div class= "NoteText" id= "Notetxt" "type=" text "ondblclick =" changename (this.id); >123</div>
</div>

JS edit Notetxt text, function is as follows:

Copy Code code 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 styles in a CSS file
function GetStyle (obj, attr)
{
if (Obj.currentstyle)
{
return obj.currentstyle[attr]; Ie
}else{
Return getComputedStyle (Obj,false) [attr]; Ff
}
}

CSS is as follows:

Copy Code code 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, here is no more explanation, the next partners can be free to play, use to their own projects to go.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.