文本框光标位置 [英] Text box cursor location

查看:129
本文介绍了文本框光标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否可以确定光标在< input type =''text''>中的位置。使用JavaScript的元素?


我想写一段代码片段,当用户按下左箭头键和光标时,它将移动到焦点到下一个文本框location已经点击了文本框'maxLength。


同样,当用户按下右箭头键(或退格键)并且光标位置已经到达开头时,我希望焦点移动到上一个文本框。文本框。


我似乎无法找到任何属性来指示光标在文本元素中的位置索引值。

感谢您的帮助!

-Frinny

I am just wondering if it is possible to determine where the cursor is located within an <input type=''text''> element using JavaScript?

I''d like to write a snippet of code that will move to the focus to the next text box when the user has pressed the left arrow key and the cursor location has hit the text box''s maxLength.

Likewise I''d like the focus to move to the previous text box when the user has pressed the right arrow key (or backspace) and the cursor location has hit the beginning of the text box.

I can''t seem to find any property that indicates what the index value of where the cursor is located at within a text element.

Thanks for your help!
-Frinny

推荐答案

您可以使用选择范围属性找到位置。参见此链接(不完全是解决方案,但您可以使用它)。
You can find the location using selection range properties. See this link (not exactly the solution, but you can work with it).



您可以找到使用选择范围属性的位置。参见此链接(不完全是解决方案,但您可以使用它)。
You can find the location using selection range properties. See this link (not exactly the solution, but you can work with it).



我很沮丧。

我发现很难找到有用的JavaScript资源。 W3C通常是我收集所有信息的地方,但是当谈到这些东西时,它并没有多大帮助。我也尝试了你推荐的链接,但无法解决我的困惑。


我想了解你发给我的那个链接的内容但是我很困惑。


你能否就document.selection.createRange()负责的方向给我一些指示。


甚至是什么document.selection。

我已经尝试查找文档对象,但对其进行模糊概述。


感谢您的帮助!


-Frinny

I am pretty frustrated with this.
I''m finding it very hard to find useful JavaScript resources. W3C is usually where I gather all my information from but when it comes to this stuff it''s not very helpful. I''ve tried your recommended links too but haven''t been able to sort out my confusion.

I''m trying to understand the content of that link you sent me but I am confused.

Could you please give me some direction on what document.selection.createRange() is responsible for.

Or even what document.selection is.
I''ve tried looking up the document object but keep getting vague overview of it.

Thanks for your help!

-Frinny


[HTML]< html>< head>

< SCRIPT LANGUAGE =" JAVASCRIPT"><! -

function show_coords(event)

{

x = event.clientX

y = event.clientY

document.getElementById(" coords")。innerHTML =(" X coords:" + x + ",Y coords:" + y)

}

- >< / SCRIPT>


< ; / HEAD>

< BODY BACKGROUND = red">

< div id = coords>< / div>< INPUT onmousemove =" show_coords (事件)">

< / body>< / html> [/ HTML]


i希望它有帮助

jx2
[HTML]<html><head>
<SCRIPT LANGUAGE="JAVASCRIPT"><!--
function show_coords(event)
{
x=event.clientX
y=event.clientY
document.getElementById("coords").innerHTML=("X coords: " + x + ", Y coords: " + y)
}
--></SCRIPT>

</HEAD>
<BODY BACKGROUND=red ">
<div id=coords></div><INPUT onmousemove="show_coords(event)">
</body></html>[/HTML]

i hope it helps
jx2


这篇关于文本框光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆