经典论坛 » 前台制作与脚本专栏 » 插入表情到光标处问题
高级会员
专长 ASP,MSSQL,Access
查看个人网站
查看详细资料
TOP
初级会员
原帖由 aolu11 于 2010-5-27 11:09 发表 editor.focus()是聚焦该文本框,并不能指定你图片插到什么地方,要是需要获取光标下的位置要用 document.selection.createRange(),然后一堆 没记,因为这是 IE only 的,其它浏览器下选择光标位置不知道..
胖
中级会员
专长 JS,C#,AS
var text=$("bcms_content"); var textLength=text.value.length; text.focus(); //判断浏览器 if(typeof document.selection!="undefined") { //IE document.selection.createRange().text='[em='+id+']' }else{ //FF兼容 text.value=text.value.substr(0,text.selectionStart)+'[em='+id+']'+text.value.substring(text.selectionStart,textLength); }