This article mainly introduces how to edit the div node name in js, and how to edit the div node name and select the style, it also selects and controls the style of IE and FF browsers, which has some reference value, for more information about how to edit the p node name in js, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:
The node html code is as follows:
The Code is as follows:
123
Edit the noteTxt text in js. The function is as follows:
The Code is as follows:
Function changeName (noteTxtId ){
Var noteTxt = document. getElementById (noteTxtId );
NoteTxt. style. display = "none"; //. style. display = "block"
Var p = 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, 'textign ');
Text. value = noteTxt. innerHTML;
P. appendChild (text );
Text. select ();
Text. onblur = function (){
NoteTxt. style. display = "block ";
NoteTxt. innerHTML = text. value;
// Text. style. display = "none ";
P. removeChild (text );
}
}
}
// Obtain the style in the css file
Function getStyle (obj, attr)
{
If (obj. currentStyle)
{
Return obj. currentStyle [attr]; // IE
} Else {
Return getComputedStyle (obj, false) [attr]; // FF
}
}
Css:
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 help you design javascript programs.