Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Nuno Amaral

Editar HTML sem Base Dados

Recommended Posts

Boas pessoal,Gostaria de saber se é possivel editar, adicionar, eliminar texto num ficheiro html sem base de dados?E usando XML, é possivel?Se sim. como?Nuno AmaralCumprimentos

Compartilhar este post


Link para o post
Compartilhar em outros sites

Acredito q o pessoal não deve ter entendido mto bem sua pergunta, pq eu não entendi =p

Compartilhar este post


Link para o post
Compartilhar em outros sites

innerHTML eh a função q adiciona tags html via JS

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bem arranjei aqui um pequeno código que muda o texto html.

 

Agora o problema é que ao fazer F5 o texto volta a ficar igual.

 

Alguém consegue por a gravar o texto editado?

 

editinplace.js

function editInPlace(el) {var oriHTML = el.innerHTML;var xy = absPos(el);editting_element = el;var div = $('edit_div','div'); div.innerHTML = '<form style="margin:0px;" onsubmit="return false;">\<input type="text" value="'+(oriHTML == '[vazio]' ? '' : oriHTML)+'" id="edit_input" onblur="editting_element\.innerHTML = this.value != \'\' ? this.value : \'[vazio]\'; \$(\'edit_div\').style.display = \'none\';" style="width:'+(el.offsetWidth+2)+'px; height:'+(el.offsetHeight+2)+'px; border:none; background-color:#c0c0c0;" /></form>';editting_element.innerHTML = '';div.style.position = 'absolute';div.style.width = 'auto';div.style.height = 'auto';div.style.top = (xy.y - 1)+'px'; div.style.left = (xy.x - 1)+'px';div.style.display = '';$("edit_input").focus();$("edit_input").select();}function $(id,tag,targetId) {var ret = document.getElementById(id) || false; if(!ret) { ret = document.createElement(tag); ret.id = id; ((document.getElementById(targetId) || false)   || document.getElementsByTagName('body')[0]).appendChild(ret); }return ret;}function absPos(el) {  for(var lx = 0, ly = 0; el != null; lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);return { 'x': lx, 'y': ly }}

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><script type="text/javascript" src="editinplace.js"></script></head><body><div onclick="editInPlace(this)">clique para editar</div><span onclick="editInPlace(this)">texto editável</span></body></html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.