input和textarea设置文本选中和获取选中文本
来源:互联网 发布:directx 11 编程 编辑:程序博客网 时间:2024/06/10 14:51
//设置文本选中高亮
function setTextSelected(inputDom, startIndex, endIndex)
{
if (inputDom.setSelectionRange)
{
inputDom.setSelectionRange(startIndex, endIndex);
}
else if (inputDom.createTextRange) //IE
{
var range = inputDom.createTextRange();
range.collapse(true);
range.moveStart('character', startIndex);
range.moveEnd('character', endIndex - startIndex-1);
range.select();
}
inputDom.focus();
}
//获取选中文本
function getSelectedText(inputDom){
if (document.selection) //IE
{
return document.selection.createRange().text;
}
else {
return inputDom.value.substring(inputDom.selectionStart,
inputDom.selectionEnd);
}
}
说明:
inputDom 为input 或者 textarea Dom 元素。
正常方式获取:
var inputDom = document.getElementById("input1");
jquery 方式获取:
var inputDom = $("#input1")[0];
- input和textarea设置文本选中和获取选中文本
- input和textarea标签的select()方法----选中文本框中的所有文本
- jquery获取选中的文本和值
- Javascript获取select的选中值和选中文本
- Javascript获取select的选中值和选中文本
- Javascript获取select的选中值和选中文本
- javascript获取select的选中值和选中文本
- Javascript获取select的选中值和选中文本
- jquery获取和设置select选中的值/文本/索引及选中事件
- javascript 设置input文本为选中状态
- textarea光标选中的文本
- 获取选中的文本
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- 如何获得outlook Express地址簿/Windows Address Book(WAB)的信息
- 函数之ExAllocatePool--内存分配
- XML解析
- VSS中添加用户与修改密码
- 数与诗的后现代对话
- input和textarea设置文本选中和获取选中文本
- Ubuntu查看当前IP地址
- iphone弹出键盘部分按键禁用
- Android类库常用类型解析
- 软件版本管理
- 函数之ExAllocatePool--内存分配
- 用WINSOCK API实现同步阻塞方式的网络通讯
- 【USACO Contest】Holiday 2010 Bonus Competition, Problem 3: Driving Out the Piggies (dotp)
- Photoshop制作Favicon.ico图标