作者starjou (周星星)
看板Web_Design
标题Re: [问题] 请问一下"点按键 出现文字在表格内"
时间Tue Dec 11 17:13:37 2007
※ 引述《siathy (hmm)》之铭言:
: 推 jonathanmeow:楼上借问一下 如果要在游标位置插入这串文字呢?谢谢 12/11 16:40
可以用 comment.selectionStart 在 onblur 事件发生时,取得游标的位置,
存入变数中,
然後在按下按钮时,把原先 comment 的 value 依照先前取得的游标位置拆开,
中间插入所要插入的字串,成为新的 comment 的值。
FireFox 试过行得通,IE 没试过,google 到的资讯说是可行。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.80.133.125
1F:→ starjou:又试了一下,其实可以省掉 onblur 时存入变数的步骤 12/11 17:19
2F:→ starjou:那个值不会跑掉 12/11 17:20
3F:推 jonathanmeow:感谢 但是看不太懂 要来去试试看先 :D 12/11 19:34
4F:→ starjou:comment.selectionStart 可以得到游标位置,假设叫 pos 12/11 22:24
5F:→ starjou:comment.value.substr(0, pos) 可以取得游标前的部份 12/11 22:24
6F:→ starjou:comment.value.substr(pos, comment.value.length-pos) 为 12/11 22:25
7F:→ starjou:游标後的部份 12/11 22:25
8F:→ starjou:把前面加中间你要加的东东加後面,指到 comment.value 12/11 22:26
9F:→ starjou:就完工了 12/11 22:26
10F:推 jonathanmeow:狂推啊 我就是看不太懂selectionStart 想说要去查 12/12 16:50
11F:→ jonathanmeow:真是太感谢了啦! 12/12 16:51