简体   繁体   中英

Getting a certain character closest from cursor in a textarea

So here is what i am trying to achieve. I have a text area. In it I can write something like:

"This is <html> and this is <java>"

What i am doing is trigger a suggestion list when a '<' is inserted. My problem is how do i get the value from the '<' until the cursor so that i can replace it if a suggestion is picked from the list. So say I start writing

"This is <ht" 

How do i get the 'ht' here if my cursor is right after it? I should be able to get achieve this even on the nth tag. So for

"This is <html> and <java> plus <ph"

I should get me "ph"

Have you tried using a caret plugin ? It has a function that allows you to replace the highlighted text.

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