简体   繁体   中英

Is it possible to make onClick event on content of text area?

I am trying to display XML data in a textarea and trying to make onClick event on content of textarea. For eg.

< textarea >Hello Web, This is simple html page.< / textarea >

Here I want to make onClick event on each 'i' character.

Please help me on this.

Well, you can't however you can use a little workaround. Add onclik event, and check caret position in the textarea, then you know between what characters it's located.

How to get it described here:

Caret position in textarea, in characters from the start

  textarea.onmouseup = textarea.onkeyup = function () {
    console.log(getCaret(textarea));
  };

it returns and index for textarea value string...

here is fiddle for you:

http://jsfiddle.net/acrashik/ydLKF/1/

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