检测光标类型 [英] detect cursor type

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

问题描述

我想要JavaScript代码检测游标类型。

I want JavaScript code to detect the cursor type.

例如,当光标悬停在textarea中时,它会从默认值更改为文本..

For example when the cursor hovers in textarea it changes from default to text ..

推荐答案

您可以使用JavaScript检测游标类型

You can detect the cursor type using JavaScript

like

<input id="sample_text" name="one" type="text" value="Sample Text" />

,JavaScript代码应如下所示:

and the JavaScript code should look something like this

$('input[id=sample_text]').click( function() {
   alert("test");   
   var ctl = document.getElementById('sample_text');
   var startPos = ctl.selectionStart;
   var endPos = ctl.selectionEnd;
   alert(startPos + ", " + endPos);
});

您还可以查看此 Jsfiddle for Js Cursor Detection

上面是Jquery代码写的,你也可以使用Vanilla JS您只需将其更改为

the above is the Jquery code written , you can also use the Vanilla JS for that you just need to change it to

<input id="sample_text" name="one" type="text" value="Sample Text" onclick="detect_cursor()" />

,JavaScript应该类似这样

and the JavaScript should look something like this

function detect_cursor() {
   alert("test");   
   var ctl = document.getElementById('sample_text');
   var startPos = ctl.selectionStart;
   var endPos = ctl.selectionEnd;
   alert(startPos + ", " + endPos);
};

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

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