1. 程式人生 > >獲取鼠標停留的位置和設置鼠標的停留的地方

獲取鼠標停留的位置和設置鼠標的停留的地方

== scrip content div lns lec ont pre ctype

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <input type="text" style="width:700px" id="test1" name="test1" value="test12設置鼠標的停留的地方設置鼠標的停留的地方設置鼠標的停留的地方設置鼠標的停留的地方設置鼠標的停留的地方設置鼠標的停留的地方3"
onclick="getthis(this);" /> <script> function getthis(obj) //獲取鼠標停留的位置 { var i = obj.selectionStart; var t = obj.selectionEnd; } function moveEnd(obj) { obj.focus();     
if (typeof obj.selectionStart == number && typeof obj.selectionEnd == number) { obj.selectionStart = obj.selectionEnd = 1; //設置鼠標的停留的地方 } } moveEnd(document.getElementById("test1")) </script> </body>
</html>

獲取鼠標停留的位置和設置鼠標的停留的地方