javascript光标定位
来源:互联网 发布:mac中qq截图快捷键 编辑:程序博客网 时间:2024/06/06 20:06
一、C#代码调用
ScriptManager.RegisterStartupScript(this, this.GetType(), "focusSearchActiveObject", "focusSearchActiveObject('" + searchFieldId + "');", true);
二、javascript代码
function focusSearchActiveObject(searchID) { var searchContainer = document.getElementById(searchID); var targetSubControl = findSubControlByName(searchContainer, getActiveNameFromCookie()); if (targetSubControl != null) { targetSubControl.focus(); if (targetSubControl.tagName.toLowerCase() == "input") { var rtextRange = targetSubControl.createTextRange(); rtextRange.moveStart("character", targetSubControl.value.length); rtextRange.collapse(true); rtextRange.select(); } } clearActiveNameOnCookie();}function findSubControlByName(containerObject, subControlName) { var targetSubControl = null; for (var i = 0; i < containerObject.childNodes.length; i++) { if (isFormControl(containerObject.childNodes[i])) { if (containerObject.childNodes[i].getAttribute("name") == subControlName) { targetSubControl = containerObject.childNodes[i]; break; } } else { if (containerObject.childNodes[i].childNodes.length > 0) { targetSubControl = findSubControlByName(containerObject.childNodes[i], subControlName); if (targetSubControl != null) { break; } } } } return targetSubControl;}function isFormControl(control) { if (control.tagName == undefined) { return false; } if (control.tagName.toLowerCase() == "input") { return true; } else if (control.tagName.toLowerCase() == "select") { return true; } else if (control.tagName.toLowerCase() == "textarea") { return true; } else { return false; }}function setActiveNameToCookie(objName) { var str = "input_currentActive=" + objName; document.cookie = str;}function getActiveNameFromCookie() { var arrStr = document.cookie.split("; "); for (var i = 0; i < arrStr.length; i++) { var temp = arrStr[i].split("="); if (temp[0] == "input_currentActive") return unescape(temp[1]); }}function clearActiveNameOnCookie() { var date = new Date(); date.setTime(date.getTime() - 10000); document.cookie = "input_currentActive=''; expires=" + date.toGMTString();}
参考:
http://www.ibulabula.com/?p=195
0 0
- javascript 光标定位
- javascript光标定位
- javascript textarea 光标定位
- JavaScript获取光标位置、定位光标位置
- JavaScript中文本光标定位
- 用JavaScript实现的文本框光标定位
- 光标定位
- 光标定位
- 光标定位
- 光标定位
- JavaScript使光标定位到文本的最后
- JavaScript使光标定位到文本的最后
- ALV 单元格光标定位
- ALV 单元格光标定位
- 光标定位(获得焦点)
- vim 光标定位
- textarea光标定位问题
- 光标定位在右边
- strtus2.3.6+guice4+jpa(hibernate4)的配置-第三篇
- UTF-8 UTF-16 Unicode编码资料
- Python中父类、子类的一点说明
- jumbo frames
- 信息的丢失导致溢出
- javascript光标定位
- spring 定时任务(一)
- Android开发学习之ImageView手势拖拽、缩放、旋转
- /t转义字符的一个特性
- Hbase之一
- jar包用途功能对照
- 一些unix命令
- Linux上的free命令详解
- apache 编译报错:undefined reference to `apr_array_clear'