input标签添加style=“-webkit-user-select: auto;”
<script>
$(function(){
//$('input').focus(focustext)
/*******用以下三行代码即可实现*******/
$('input').click(function(){
this.selectionStart = 0;
this.selectionEnd = this.val().length;
})
})
function focustext() {
var input = this;
setTimeout(function(){ input.selectionStart = 0; input.selectionEnd = input.val().length; }, 100)
}
</script>
本文介绍了一种使用JavaScript实现的简单方法,当点击输入框时自动全选其中的文本内容,提高用户体验。通过简单的几行代码即可实现该功能。
2387

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



