<br> var array1 = new Array();//将原始数据分割成数组<br> var arrays = new Array();//将array1中偶数项存入此数组<br> var num =""; //记录当前点击的是第几个<a><br> var div = document.createElement("DIV");<br> div.id = "aaa1";<br> div.style.backgroundColor = "#9ef1fa";<br> div.style.borderLeft = "5px outset #4ec5f5";<br> div.style.borderTop = "5px outset #4ec5f5";<br> div.style.borderRight = "2px outset #4ec5f5";<br> div.style.visibility = "hidden";<br> div.style.position = "absolute";<br> document.body.appendChild(div);</p> <pre><code> function getValue() { document.getElementById("textarea1").value = ""; array1.splice(0, array1.length); arrays.splice(0, arrays.length); var file = document.getElementById("textarea").value var a = file; do { var a = a.replace("[", "\\"); a = a.replace("]", "\\"); } while (a.indexOf("[") > 0 || a.indexOf("]") > 0) array1 = a.split("\\"); var content = ""; for (var i = 0; i < array1.length; i++) { if (i % 2 == 1) { var array = array1[i].split("/"); if (arrays.length == 0) { arrays[0] = array; } else { arrays[arrays.length] = array; } } if (i % 2 == 0) { content += array1[i]; } else { content += "<a id=" + "\"" + parseInt(i / 2) + "\"" + " onclick=" + "\"" + "qwe(" + parseInt(i / 2) + ")" + "\"" + " onmouseleave=" + "\"" + "qwe1(" + parseInt(i / 2) + ")" + "\"" + " style=" + "\"" + "color:Red;text-decoration:none" + "\"" + ">" + arrays[parseInt(i / 2)][0] + "</a>"; } } var a = document.createElement("<span id='aaa3'>"); a.innerHTML = content; window.textarea1.appendChild(a); } var timeOut = null; function qwe(evt) { num =evt; clearTimeout(timeOut); if (document.getElementById("aaa2") != null) { document.getElementById("aaa1").removeChild(document.getElementById("aaa2")); } if (document.getElementById("aaa2") != null) { var length = document.getElementById("aaa2").childNodes.length; for (var i = 0; i < length; i++) { document.getElementById("aaa2").removeChild(document.getElementById("aaa2").childNodes[i]); break; } } else { var ul = document.createElement("ul"); ul.id = "aaa2"; } var o = document.getElementById("aaa1"); for (var i = 0; i < arrays[evt].length; i++) { var li = document.createElement("<li style='margin-right:20px; margin-left:-20px; list-style-type:none; padding:0px;cursor:pointer;' onmouseover='qwe4(this)' onmouseleave ='qwe(this)' onclick='qwe2()'>"); li.innerHTML = arrays[evt][i]; ul.appendChild(li);; } o.appendChild(ul); var a = "#" + evt; var thisLi = $(a); showSubList(a); } function qwe4(o) { o.style.color = "Green"; } function qwe5(o) { o.style.color = "Black"; } function qwe1(evt) { var a = "#" + evt; var thisLi = $(a); timeOut = setTimeout(function () { hideSubList(thisLi); }, 1000); $("#aaa1").hover(function (e) { clearTimeout(timeOut); }, function () { clearTimeout(timeOut); timeOut = setTimeout(function () { hideSubList(thisLi); }, 100); }); } var showSubList = function (a) { var o = document.getElementById("aaa1"); o.style.visibility = "visible"; $("#aaa1").css({ top: top, opacity: 0 }).show().stop().animate({ top: $(a).offset().top, left: $(a).offset().left + $(a).width(), opacity: 1 }); }; var hideSubList = function (thisli) { var o = document.getElementById("aaa1"); o.style.visibility = "hidden"; }; function qwe2() { var text = event.srcElement.innerHTML; var curText = $("#aaa3").html(); alert(curText); var starta = "<A id=" + num + ""; alert(starta); var startindex = curText.indexOf(starta); var enda = "</a>"; var endindex = curText.indexOf(enda, startindex); var replaceText = "<a id='" + num + "' onclick='qwe(" + num + ")' onmouseleave='qwe1(" + num + ")' style='color:Red;text-decoration:none'>" + text + "</a>"; var content = curText.substr(0, startindex) + replaceText + curText.substr(endindex + enda.length, curText.length - endindex - enda.length); window.textarea1.removeChild(document.getElementById("aaa3")); var a = document.createElement("span"); a.id = "aaa3"; a.innerHTML = content; window.textarea1.appendChild(a); hideSubList(); } </script> </code></pre> <p></body></p>