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
搜索
積分與排名
積分 - 1031348
排名 - 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水平居中和垂直居中解決方案(轉)(85882)
2.?超強1000個jquery極品插件!(轉)(48117)
3.?信用卡卡號列表(用于測試)(38725)
4.?四大咨詢公司 VS 四大會計師事務所(20901)
5.?IE下div使用margin:0px auto不居中的原因(19279)
評論排行榜
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
閱讀(4834)
評論(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
主站蜘蛛池模板:
国产v精品成人免费视频400条
|
国产精品美女免费视频观看
|
久久成人国产精品免费软件
|
夜夜亚洲天天久久
|
97碰公开在线观看免费视频
|
亚洲色图.com
|
手机看黄av免费网址
|
亚洲乱码在线观看
|
女人被男人桶得好爽免费视频
|
亚洲精品无码av片
|
四虎国产精品免费视
|
亚洲免费日韩无码系列
|
亚洲热线99精品视频
|
在线成人爽a毛片免费软件
|
亚洲一区二区三区久久久久
|
成年女人午夜毛片免费看
|
亚洲AV成人片无码网站
|
亚洲精品国产精品乱码不卡
|
中国国产高清免费av片
|
色拍自拍亚洲综合图区
|
成人男女网18免费视频
|
国产精品亚洲小说专区
|
亚洲精品午夜国产VA久久成人
|
久久久久久一品道精品免费看
|
亚洲人成日本在线观看
|
国产jizzjizz视频免费看
|
精品多毛少妇人妻AV免费久久
|
亚洲三级中文字幕
|
女人与禽交视频免费看
|
一个人看的www免费在线视频
|
亚洲国产精品无码久久久蜜芽
|
精品无码免费专区毛片
|
日韩色日韩视频亚洲网站
|
国产亚洲综合色就色
|
毛片免费在线观看网址
|
精品多毛少妇人妻AV免费久久
|
亚洲一区在线观看视频
|
亚洲精品线路一在线观看
|
五月亭亭免费高清在线
|
四虎一区二区成人免费影院网址
|
国产综合亚洲专区在线
|