点击包含值的输入字段,光标应指向末尾。 这实际上是浏览器的默认行为。但是在iPhone和iPad中,当用户点击输入边框(上边框)时,光标出现在输入字段的开头。下面是一个示例字段,我在其中尝试了几个建议......但没有运气。
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale = 1 , maximum-scale=1, , maximum-scale = 1, user-scalable = 0">
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<script>
$('document').ready(function(){
$('input').focus(function(){
this.selectionStart = this.selectionEnd = this.value.length;
console.log("yp");
});
});
</script>
<style>
body{
font-size: 20px;
}
input{
padding: 10px;
font-size: 20px;
}
</style>
</head>
<body>
<form action="">
<br>
Username: <input type="text" name="usrname" value="Dipen" onfocus="this.value = this.value;">
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
提前致谢!!