简体   繁体   中英

Does anyone know how to change the character of a textfield caret with javascript?

Like the title reads, I want to change the character of a caret. Maybe make it a letter or something?

Thanks.

You can do something near this, but its very dificult.

  1. In you textfield bind a event to keydown, for example.
  2. Each char typed, you slide a floating <img> above textarea.
  3. If user click in textarea, update position getting X and Y from onclick.

Obs: the font must be monospaced. Ex: if every font have 20px and user press backspace, you slide this gif to the left 20px.


EDIT

I just made a hello world, in jsfiddle .

Of course, it's an example, but test typing and use backspace and enter to see caret go back and foward.

In this example there are a lot of bugs to fix, like:

  • Use of <backspace> that cleans all line

  • Use of arrows that in overflow textarea margins

  • Use of mouse must update caret position...

在HTML / JavaScript中是不可能的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM