Detect   and space with JavaScript

前端 未结 3 1394
忘了有多久
忘了有多久 2021-01-18 16:59

I\'m trying to read the content of a contentEditable div and extract the currently active word. ie. the word which was just entered or one which was modified. <

相关标签:
3条回答
  • 2021-01-18 17:44

    I found a workaround. Previously, I was using innerHTML to get the contents. Now, I'm using targ.firstChild.nodeValue where targ is the element whose content is needed.Then checking with str.charCodeAt(i)==32 || str.charCodeAt(i)==160 .

    This works well.

    0 讨论(0)
  • 2021-01-18 17:58

    I think what you are looking is here : non-breaking space in Javascript.

    0 讨论(0)
  • 2021-01-18 18:03

    String.fromCharCode(160) worked for me. It stands for &nbsp; character. if(str == ' ') was not working in if condition, neither did trim(); but if(str == String.fromCharCode(160)) worked.

    For checking normal space use if(str.trim() == '')

    0 讨论(0)
提交回复
热议问题