detect cursor type

前端 未结 4 1163
渐次进展
渐次进展 2021-01-11 16:46

I want JavaScript code to detect the cursor type.

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

4条回答
  •  无人及你
    2021-01-11 17:37

    You can detect the cursor type using JavaScript

    like

    
    

    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);
    });
    

    you can also look at this Jsfiddle for Js Cursor Detection

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

    
    

    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);
    };
    

提交回复
热议问题