本人不怎么会写JS,但是会搜索,这里找到了些别人写好的东西:
select(document, tanchu);
/*=select[[
*
* 跨浏览器选中文字事件
* @param
* object o 响应选中事件的DOM对象,required
* function fn(sText,target,mouseP)选中文字非空时的回调函数,required
* |-@param
* |-sText 选中的文字内容
* |-target 触发mouseup事件的元素
* |-mouseP 触发mouseup事件时鼠标坐标
*/
function select(o, fn){
o.onmouseup = function(e){
var event = window.event || e;
var target = event.srcElement ? event.srcElement : event.target;
if (/input|textarea/i.test(target.tagName) && /firefox/i.test(navigator.userAgent)) {
//Firefox在文本框内选择文字
var staIndex=target.selectionStart;
var endIndex=target.selectionEnd;
if(staIndex!=endIndex){
var sText=target.value.substring(staIndex,end