开发者

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开发者_StackOverflow社区 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...


That's not possible in HTML/JavaScript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜