设置所选文本在 IE 中可见
set the selected text visible in IE
1 Programmatically inserting text into a text box
2 Setting the caret to the end.
3 Making the caret visible (i.e. scroll the text box content)
4 Select some of the text from last programmatically,
5 **set the selected text visible.** (i.e. scroll the text box content)
我可以做1,2,3,4.但我做不到 5.此问题仅存在于IE9+中
任何解决方案??
setSelectionRange() 并不完全支持 IE。
所以在谷歌搜索了很多之后,我用下面的代码替换了它,它对我有用。
function setSelection(field, start, charsTobeSelected) {
end = start + charsTobeSelected;
if (field.createTextRange) {
var selRange = field.createTextRange();
selRange.collapse(true);
selRange.moveStart('character', start);
selRange.moveEnd('character', end);
selRange.select();
field.focus();
} else if (field.setSelectionRange) {
field.focus();
field.setSelectionRange(start, end);
} else if (typeof field.selectionStart != 'undefined') {
field.selectionStart = start;
field.selectionEnd = end;
field.focus();
}
}
相关文章:
- 我的剧本赢了'不能在IE中工作(甚至9)?修改复制文本的简单javascript
- 动态文本大小JavaScript在IE中不起作用
- 文本区域在IE 10中填充了[object HTMLMetaElement]
- 从IE中的文本框中获取未选中的文本
- 阻止选择在IE中工作但不在Chrome中工作的文本
- Lotus Notes web表单-IE中的文本区域问题
- 如果使用javascript创建,则无法在ie 11中键入输入类型文本!:(
- 无法使文本插件在IE中使用requirejs
- 使用javascript(IE bug?)在文本区域插入新行
- 如果在 IE 中最后附加光标,则在光标位置的文本区域中插入文本
- 调用 blur() 时,IE 中文本区域和输入中的光标闪烁
- 用于右键单击<输入>或<文本区域>上的删除的 IE 事件
- 是否可以检测IE何时忽略xml文档中的空白文本节点
- 为什么选择只显示IE 9中选项文本的第一个字符
- (IE 特定)如何确定输入的文本是否比输入元素的宽度长
- 删除谷歌浏览器和IE浏览器中文本区域中的选定文本
- 设置所选文本在 IE 中可见
- IE文本区域中呈现的变量去掉了格式
- setcontent将文本插入到IE文本区域的开头
- IE文本模糊时使用jQuery fadeIn