Sealyu
--- 博客已遷移至:
http://www.sealyu.com/blog
BlogJava
::
首頁
::
新隨筆
::
聯系
::
聚合
::
管理
::
618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks
<
2010年6月
>
日
一
二
三
四
五
六
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(14)
給我留言
查看公開留言
查看私人留言
隨筆分類
Apple(11)
(rss)
CSS(48)
(rss)
Eclipse SWT/JFace RCP(11)
(rss)
EJB(9)
(rss)
EXTJS(11)
(rss)
Flex+ActionScript(40)
(rss)
Groovy & Grails(2)
(rss)
GWT(8)
(rss)
Hibernate(18)
(rss)
iPhone(51)
(rss)
Javascript(23)
(rss)
Java基礎(36)
(rss)
JQuery(13)
(rss)
Linux(54)
(rss)
Maven(14)
(rss)
PHP(15)
(rss)
Python(34)
(rss)
Seam(46)
(rss)
SEO(6)
(rss)
Spring(24)
(rss)
Struts(6)
(rss)
web(50)
(rss)
web服務器(27)
(rss)
中醫(11)
(rss)
單元測試(1)
(rss)
娛樂(19)
(rss)
數據庫(23)
(rss)
版本控制(6)
(rss)
系統架構(11)
(rss)
綜合(38)
(rss)
英語(31)
(rss)
設計模式(12)
(rss)
讀書(15)
(rss)
項目管理(9)
(rss)
隨筆檔案
2011年1月 (3)
2010年12月 (9)
2010年11月 (20)
2010年10月 (21)
2010年9月 (26)
2010年8月 (28)
2010年7月 (6)
2010年6月 (12)
2010年5月 (22)
2010年4月 (21)
2010年3月 (17)
2010年2月 (16)
2010年1月 (37)
2009年12月 (46)
2009年11月 (21)
2009年10月 (21)
2009年9月 (38)
2009年8月 (14)
2009年7月 (10)
2009年6月 (3)
2009年5月 (19)
2009年4月 (25)
2009年3月 (29)
2009年2月 (15)
2009年1月 (12)
2008年12月 (16)
2008年11月 (41)
2008年10月 (1)
2008年9月 (9)
2008年8月 (14)
2008年7月 (40)
2008年6月 (9)
2008年5月 (3)
2008年4月 (75)
友情鏈接
androider的博客
Andy Yao
Eric Zhou的博客
Liu Huifang's Blog
繼棟的博客
阿謝的Blog
搜索
積分與排名
積分 - 1030726
排名 - 31
最新評論
1.?re: 慎用java.util.Collections.copy()方法[未登錄]
樓主誤認。。二樓正解
是Arrays.asList()....不是Array.asList()
--yf
2.?re: django form的widgets類型列表
額請問請問其味無窮而且
--企鵝
3.?re: Django和Ajax教程(轉)
good!
--~
4.?re: JSF Validator(轉)
adsfasdfasdfadsfsdfadsf
--asdfdsdfsadfasdfasdfsdf
5.?re: IE下div使用margin:0px auto不居中的原因
用到了,謝謝~~
--游客
閱讀排行榜
1.?CSS水平居中和垂直居中解決方案(轉)(85880)
2.?超強1000個jquery極品插件!(轉)(48115)
3.?信用卡卡號列表(用于測試)(38719)
4.?四大咨詢公司 VS 四大會計師事務所(20898)
5.?IE下div使用margin:0px auto不居中的原因(19277)
評論排行榜
1.? 2009 年度最佳 jQuery 插件(轉)(19)
2.?超強1000個jquery極品插件!(轉)(15)
3.?IE屏蔽window.open()窗口的解決辦法(13)
4.?iphone版本的九宮格日記已經上線發售了!(12)
5.?信用卡卡號列表(用于測試)(11)
js獲取光標位置(轉)
/**
* 獲取光標所在的字符位置
* @param obj 要處理的控件, 支持文本域和輸入框
* @author hotleave
*/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=GBK" /> <title>js獲取光標位置</title> <script type="text/javascript"> /** * 獲取光標所在的字符位置 * @param obj 要處理的控件, 支持文本域和輸入框 * @author hotleave */ function getPosition(obj){ //alert(obj.tagName); var result = 0; if(obj.selectionStart){ //非IE瀏覽器 result = obj.selectionStart }else{ //IE var rng; if(obj.tagName == "TEXTAREA"){ //如果是文本域 rng = event.srcElement.createTextRange(); rng.moveToPoint(event.x,event.y); }else{ //輸入框 rng = document.selection.createRange(); } rng.moveStart("character",-event.srcElement.value.length); result = rng.text.length; } return result; } function getValue(obj){ var pos = getPosition(obj); //alert(pos); alert(obj.value.substr(0,pos)+" [這里是添加的內容] "+obj.value.substr(pos,obj.value.length)); } </script> </head> <body> <input type="text" value="你好,Amethyst!" onmouseup="getValue(this)" style="display:block"> <textarea rows="6" cols="60" onmouseup="getValue(this)">Amethyst, 你好.</textarea> </body> </html>
復制代碼
另存代碼
提示:您 可以先修改部分代碼再運行
<html> <head> <title>js獲取光標位置</title> <style> body,td{ font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; } </style> <script type="text/javascript"> var start=0; var end=0; function add(){ var textBox = document.getElementById("ta"); var pre = textBox.value.substr(0, start); var post = textBox.value.substr(end); textBox.value = pre + document.getElementById("inputtext").value + post; } function savePos(textBox){ //如果是Firefox(1.5)的話,方法很簡單 if(typeof(textBox.selectionStart) == "number"){ start = textBox.selectionStart; end = textBox.selectionEnd; } //下面是IE(6.0)的方法,麻煩得很,還要計算上'"n' else if(document.selection){ var range = document.selection.createRange(); if(range.parentElement().id == textBox.id){ // create a selection of the whole textarea var range_all = document.body.createTextRange(); range_all.moveToElementText(textBox); //兩個range,一個是已經選擇的text(range),一個是整個textarea(range_all) //range_all.compareEndPoints()比較兩個端點,如果range_all比range更往左(further to the left),則 //返回小于0的值,則range_all往右移一點,直到兩個range的start相同。 // calculate selection start point by moving beginning of range_all to beginning of range for (start=0; range_all.compareEndPoints("StartToStart", range) < 0; start++) range_all.moveStart('character', 1); // get number of line breaks from textarea start to selection start and add them to start // 計算一下"n for (var i = 0; i <= start; i ++){ if (textBox.value.charAt(i) == '"n') start++; } // create a selection of the whole textarea var range_all = document.body.createTextRange(); range_all.moveToElementText(textBox); // calculate selection end point by moving beginning of range_all to end of range for (end = 0; range_all.compareEndPoints('StartToEnd', range) < 0; end ++) range_all.moveStart('character', 1); // get number of line breaks from textarea start to selection end and add them to end for (var i = 0; i <= end; i ++){ if (textBox.value.charAt(i) == '"n') end ++; } } } document.getElementById("start").value = start; document.getElementById("end").value = end; } </script> </head> <body> <form action="a.cgi"> <table border="1" cellspacing="0" cellpadding="0"> <tr> <td>start: <input type="text" id="start" size="3"/></td> <td>end: <input type="text" id="end" size="3"/></td> </tr> <tr> <td colspan="2"> <textarea id="ta" onKeydown="savePos(this)" onKeyup="this.value=this.value.replace(/[",]/g,',');savePos(this);" onmousedown="savePos(this)" onmouseup="savePos(this)" onfocus="savePos(this)" rows="14" cols="50"></textarea> </td> </tr> <tr> <td><input type="text" id="inputtext" /></td> <td><input type="button" onClick="add()" value="Add Text"/></td> </tr> </table> </form> </body> </html>
復制代碼
另存代碼
提示:您 可以先修改部分代碼再運行
posted on 2010-06-22 23:17
seal
閱讀(4833)
評論(0)
編輯
收藏
所屬分類:
Javascript
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
js獲取光標位置(轉)
FCKeditor: Resolve “FCKeditorAPI is not defined” issue
IE和Safari中重命名html元素需要注意的問題
prototype.js 的 Ajax.updater 的 用法(轉)
Detecting Internet Explorer More Effectively
Using the navigator object to detect client's browser
IE 和 Firefox中取得createRange()的起點和終點的值
Setting the name attribute in IE's DOM
Inserting at the cursor using JavaScript
15個使用jQuery實現圖片幻燈片效果的JS源碼(轉)
Powered by:
BlogJava
Copyright © seal
主站蜘蛛池模板:
精品国产_亚洲人成在线高清
|
国产精品成人免费视频网站京东
|
免费一级毛片在线播放不收费
|
亚洲资源最新版在线观看
|
亚洲无砖砖区免费
|
亚洲成av人片不卡无码
|
国产精品视频免费
|
亚洲高清有码中文字
|
四色在线精品免费观看
|
美女被免费视频网站
|
亚洲高清无码在线观看
|
中文字幕在线成人免费看
|
亚洲韩国精品无码一区二区三区
|
久久久久久免费一区二区三区
|
亚洲gv猛男gv无码男同短文
|
天黑黑影院在线观看视频高清免费
|
国产亚洲婷婷香蕉久久精品
|
精品一区二区三区无码免费视频
|
亚洲成电影在线观看青青
|
AA免费观看的1000部电影
|
国产精品亚洲av色欲三区
|
久久精品国产亚洲AV不卡
|
日韩人妻无码精品久久免费一
|
亚洲AV成人无码天堂
|
四虎永久精品免费观看
|
成人一区二区免费视频
|
亚洲日本乱码一区二区在线二产线
|
日韩免费视频网站
|
久久久免费观成人影院
|
亚洲男人天堂影院
|
五月婷婷亚洲综合
|
无码中文字幕av免费放dvd
|
亚洲人AV在线无码影院观看
|
综合亚洲伊人午夜网
|
222www免费视频
|
激情吃奶吻胸免费视频xxxx
|
国产aⅴ无码专区亚洲av
|
成人免费午夜在线观看
|
成人自慰女黄网站免费大全
|
亚洲精品123区在线观看
|
亚洲伊人色欲综合网
|