var content = "input元素";
content.focus();
var len = content.value.length;
if (document.selection) {
var sel = content.createTextRange();
sel.moveStart('character', len);
sel.collapse();
sel.select();
} else if (typeof content.selectionStart == 'number' && typeof content.selectionEnd == 'number') {
content.selectionStart = content.selectionEnd = len;
}
content.focus();
var len = content.value.length;
if (document.selection) {
var sel = content.createTextRange();
sel.moveStart('character', len);
sel.collapse();
sel.select();
} else if (typeof content.selectionStart == 'number' && typeof content.selectionEnd == 'number') {
content.selectionStart = content.selectionEnd = len;
}

本文介绍了一种在网页中实现输入框内文字自动选中的方法,适用于不同浏览器环境。通过JavaScript操作input元素,实现了光标定位及文本选择的功能。
7716

被折叠的 条评论
为什么被折叠?



