即时更新 jQuery-highlightTextarea
Update jQuery-highlightTextarea on-the-fly
我正在尝试即时更新 jQuery 插件 "highlightTextarea",但它无法正常工作。
我可以按预期初始化 textarea,但 textarea 不关心更新。
<textarea id="textarea">this is a test</textarea>
$('#textarea').highlightTextarea({ words: ['this'] }) // <--- working
$('#textarea').highlightTextarea({ words: ['is'] }) // <--- not working
$('#textarea').highlightTextarea({ words: ['a'] }) // <--- not working
我为你准备了一点fiddle。希望任何人都可以帮助我解决这个问题。提前致谢。
编辑:这是解决方案:首先 'destroy' textarea。 fiddle
您只需要先使用destroy
选项:
$('#textarea').highlightTextarea('destroy')
$('#textarea').highlightTextarea({ words: [split[counter]], wordsOnly:true })
为了检查该选项的工作原理,您可以查看 https://github.com/garysieling/jquery-highlighttextarea/blob/master/jquery.highlighttextarea.js
处的行 185
我正在尝试即时更新 jQuery 插件 "highlightTextarea",但它无法正常工作。 我可以按预期初始化 textarea,但 textarea 不关心更新。
<textarea id="textarea">this is a test</textarea>
$('#textarea').highlightTextarea({ words: ['this'] }) // <--- working
$('#textarea').highlightTextarea({ words: ['is'] }) // <--- not working
$('#textarea').highlightTextarea({ words: ['a'] }) // <--- not working
我为你准备了一点fiddle。希望任何人都可以帮助我解决这个问题。提前致谢。
编辑:这是解决方案:首先 'destroy' textarea。 fiddle
您只需要先使用destroy
选项:
$('#textarea').highlightTextarea('destroy')
$('#textarea').highlightTextarea({ words: [split[counter]], wordsOnly:true })
为了检查该选项的工作原理,您可以查看 https://github.com/garysieling/jquery-highlighttextarea/blob/master/jquery.highlighttextarea.js
处的行185