2 jimaku753 jimaku753 于 2014.07.25 10:42 提问

判断鼠标是否在层里,qwe2里的num是[object]














<br> var array1 = new Array();//将原始数据分割成数组<br> var arrays = new Array();//将array1中偶数项存入此数组<br> var num =&quot;&quot;; //记录当前点击的是第几个<a><br> var div = document.createElement(&quot;DIV&quot;);<br> div.id = &quot;aaa1&quot;;<br> div.style.backgroundColor = &quot;#9ef1fa&quot;;<br> div.style.borderLeft = &quot;5px outset #4ec5f5&quot;;<br> div.style.borderTop = &quot;5px outset #4ec5f5&quot;;<br> div.style.borderRight = &quot;2px outset #4ec5f5&quot;;<br> div.style.visibility = &quot;hidden&quot;;<br> div.style.position = &quot;absolute&quot;;<br> document.body.appendChild(div);</p> <pre><code> function getValue() { document.getElementById(&quot;textarea1&quot;).value = &quot;&quot;; array1.splice(0, array1.length); arrays.splice(0, arrays.length); var file = document.getElementById(&quot;textarea&quot;).value var a = file; do { var a = a.replace(&quot;[&quot;, &quot;\\&quot;); a = a.replace(&quot;]&quot;, &quot;\\&quot;); } while (a.indexOf(&quot;[&quot;) &gt; 0 || a.indexOf(&quot;]&quot;) &gt; 0) array1 = a.split(&quot;\\&quot;); var content = &quot;&quot;; for (var i = 0; i &lt; array1.length; i++) { if (i % 2 == 1) { var array = array1[i].split(&quot;/&quot;); if (arrays.length == 0) { arrays[0] = array; } else { arrays[arrays.length] = array; } } if (i % 2 == 0) { content += array1[i]; } else { content += &quot;&lt;a id=&quot; + &quot;\&quot;&quot; + parseInt(i / 2) + &quot;\&quot;&quot; + &quot; onclick=&quot; + &quot;\&quot;&quot; + &quot;qwe(&quot; + parseInt(i / 2) + &quot;)&quot; + &quot;\&quot;&quot; + &quot; onmouseleave=&quot; + &quot;\&quot;&quot; + &quot;qwe1(&quot; + parseInt(i / 2) + &quot;)&quot; + &quot;\&quot;&quot; + &quot; style=&quot; + &quot;\&quot;&quot; + &quot;color:Red;text-decoration:none&quot; + &quot;\&quot;&quot; + &quot;&gt;&quot; + arrays[parseInt(i / 2)][0] + &quot;&lt;/a&gt;&quot;; } } var a = document.createElement(&quot;&lt;span id=&#39;aaa3&#39;&gt;&quot;); a.innerHTML = content; window.textarea1.appendChild(a); } var timeOut = null; function qwe(evt) { num =evt; clearTimeout(timeOut); if (document.getElementById(&quot;aaa2&quot;) != null) { document.getElementById(&quot;aaa1&quot;).removeChild(document.getElementById(&quot;aaa2&quot;)); } if (document.getElementById(&quot;aaa2&quot;) != null) { var length = document.getElementById(&quot;aaa2&quot;).childNodes.length; for (var i = 0; i &lt; length; i++) { document.getElementById(&quot;aaa2&quot;).removeChild(document.getElementById(&quot;aaa2&quot;).childNodes[i]); break; } } else { var ul = document.createElement(&quot;ul&quot;); ul.id = &quot;aaa2&quot;; } var o = document.getElementById(&quot;aaa1&quot;); for (var i = 0; i &lt; arrays[evt].length; i++) { var li = document.createElement(&quot;&lt;li style=&#39;margin-right:20px; margin-left:-20px; list-style-type:none; padding:0px;cursor:pointer;&#39; onmouseover=&#39;qwe4(this)&#39; onmouseleave =&#39;qwe(this)&#39; onclick=&#39;qwe2()&#39;&gt;&quot;); li.innerHTML = arrays[evt][i]; ul.appendChild(li);; } o.appendChild(ul); var a = &quot;#&quot; + evt; var thisLi = $(a); showSubList(a); } function qwe4(o) { o.style.color = &quot;Green&quot;; } function qwe5(o) { o.style.color = &quot;Black&quot;; } function qwe1(evt) { var a = &quot;#&quot; + evt; var thisLi = $(a); timeOut = setTimeout(function () { hideSubList(thisLi); }, 1000); $(&quot;#aaa1&quot;).hover(function (e) { clearTimeout(timeOut); }, function () { clearTimeout(timeOut); timeOut = setTimeout(function () { hideSubList(thisLi); }, 100); }); } var showSubList = function (a) { var o = document.getElementById(&quot;aaa1&quot;); o.style.visibility = &quot;visible&quot;; $(&quot;#aaa1&quot;).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(&quot;aaa1&quot;); o.style.visibility = &quot;hidden&quot;; }; function qwe2() { var text = event.srcElement.innerHTML; var curText = $(&quot;#aaa3&quot;).html(); alert(curText); var starta = &quot;&lt;A id=&quot; + num + &quot;&quot;; alert(starta); var startindex = curText.indexOf(starta); var enda = &quot;&lt;/a&gt;&quot;; var endindex = curText.indexOf(enda, startindex); var replaceText = &quot;&lt;a id=&#39;&quot; + num + &quot;&#39; onclick=&#39;qwe(&quot; + num + &quot;)&#39; onmouseleave=&#39;qwe1(&quot; + num + &quot;)&#39; style=&#39;color:Red;text-decoration:none&#39;&gt;&quot; + text + &quot;&lt;/a&gt;&quot;; var content = curText.substr(0, startindex) + replaceText + curText.substr(endindex + enda.length, curText.length - endindex - enda.length); window.textarea1.removeChild(document.getElementById(&quot;aaa3&quot;)); var a = document.createElement(&quot;span&quot;); a.id = &quot;aaa3&quot;; a.innerHTML = content; window.textarea1.appendChild(a); hideSubList(); } &lt;/script&gt; </code></pre> <p></body></p>
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!