如何获取输入中文本插入符号的索引?
-> 选择开始
<!doctype html> <html> <head> <meta charset = "utf-8"> <script type = "text/javascript"> window.addEventListener ("load", function () { var input = document.getElementsByTagName ("input"); input[0].addEventListener ("keydown", function () { alert ("Caret position: " + this.selectionStart); // You can also set the caret: this.selectionStart = 2; }); }); </script> <title>Test</title> </head> <body> <input type = "text"> </body> </html>