Este artigo descreve o método de editar nomes de nó div por JS. Compartilhe para sua referência. O método de implementação específico é o seguinte:
O código HTML do nó é o seguinte:
Copie o código da seguinte forma: <div id = "img_1">
<input type = "image" src = "img/cump.png"> </input>
<div id = "notetxt" type = "text" ondblClick = "ChanGename (this.id);"> 123 </div>
</div>
JS Editar Texto NoteTxt, a função é a seguinte:
A cópia do código é a seguinte: Function ChanGename (NoteTxtId) {
var noteTxt = document.getElementById (notetxtId);
notettxt.style.display = "nenhum"; //. style.display = "bloco"
var div = noteTxt.parentNode;
if (! document.getElementById ("NoteInput")) {
var text = document.createElement ("entrada");
text.type = "text";
text.id = "NoteInput";
text.style.width = getStyle (notetxt, 'width');
text.style.Height = getStyle (NoteTxt, 'altura');
text.style.margintop = getStyle (notetxt, 'margintop');
text.style.TexTalign = getStyle (NoteTxt, 'textalign');
text.value = notetxt.innerhtml;
div.appendChild (texto);
text.Select ();
text.onblur = function () {
notetxt.style.display = "bloco";
notettxt.innerhtml = text.value;
//text.style.display= "nenhum";
div.RemoVechild (texto);
}
}
}
// Obtenha o estilo no arquivo CSS
função getStyle (obj, att)
{
if (obj.currentstyle)
{
retornar obj.currentStyle [att]; // ou seja
}outro{
retornar getComputedStyle (obj, false) [att]; // ff
}
}
CSS é o seguinte:
Copie o código da seguinte forma: .img_1 {
Largura: 80px;
Altura: 70px;
Posição: Absoluto;
}
.notetext {
Largura: 80px;
Altura: 15px;
Alinhamento de texto: centro;
Margin-top: 70px;
Break Word: Break-All;
}
Espero que este artigo seja útil para a programação JavaScript de todos.