Inserting a text where cursor is using Javascript/jquery

前端 未结 13 2647
盖世英雄少女心
盖世英雄少女心 2020-11-22 03:58

I have a page with a lot of textboxes. When someone clicks a link, i want a word or two to be inserted where the cursor is, or appended to the textbox which has the focus.<

13条回答
  •  一向
    一向 (楼主)
    2020-11-22 04:23

    How to insert some Text to current cursor position of a TextBox through JQuery and JavaScript

    Process

    1. Find the Current Cursor Position
    2. Get the Text to be Copied
    3. Set the Text Over there
    4. Update the Cursor position

    Here I have 2 TextBoxes and a Button. I have to Click on a certain position on a textbox and then click on the button to paste the text from the other textbox to the the position of the previous textbox.

    Main issue here is that getting the current cursor position where we will paste the text.

    //Textbox on which to be pasted
    
    
    //Textbox from where to be pasted
    
    
    
    //Button on which click the text to be pasted
    
    
    
    
    

提交回复
热议问题