日期:2014-05-18  浏览次数:20434 次

询问DIV的问题,急急急急急,50分送上
比如有一个文本框和有一个div
我想实现单击div取得文本框中选中的文本
请问怎么做

代码如下
<input   id= "Text1 "   type= "text "   />

<div   onclick= "alert(document.selection.createRange().text); "> 单击 </div>

<button   onclick= "alert(document.selection.createRange().text); "> </button>

用按钮就可以
但是用div就不行
不知道如何实现

------解决方案--------------------
改成mousedown事件就好了

<input id= "Text1 " type= "text " />

<div onmousedown= "alert(document.selection.createRange().text); "> 单击 </div>