Leggile però le risposte che ti diamo, sennò diventa snervante!
codice:<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Pagina vuota</title> <script type="text/javascript"> function leggiRange() { var sTxtContent, oRange, oMyNode = document.getElementById("esempio"); if (document.all) { sTxtContent = oMyNode.innerText; } else { oRange = document.createRange(); oRange.selectNodeContents(oMyNode); sTxtContent = oRange.toString(); } alert(oRange.toString()); } function leggiNodeValue() { alert(document.getElementById("esempio").firstChild.nodeValue); } function leggiScorrendo() { function ricorsiva(oNode) { var sValue = ""; if (oNode.nodeType !== 3) { for (var iNode = oNode.firstChild; iNode; iNode = iNode.nextSibling) { sValue += iNode.nodeType === 3 ? iNode.nodeValue : ricorsiva(iNode); } } else { sValue = oNode.nodeValue; } return sValue; } var oMyNode = document.getElementById("esempio"); alert(ricorsiva(oMyNode)); } </script> <style type="text/css"> .intLink { cursor: pointer; text-decoration: underline; color: #0000ff; } </style> </head> <body> <p id="esempio">Contenuto di esempio. Questo testo è in corsivo. Quest'altro è tornato normale.</p> [ <span class="intLink" onclick="leggiRange();">Leggi per mezzo di un range</span> | <span class="intLink" onclick="leggiNodeValue();">Leggi con nodeValue</span> | <span class="intLink" onclick="leggiScorrendo();">Leggi scorrendo il nodeValue di tutti i nodi figli.</span> </body> </html>


Rispondi quotando