是否可以使用javascript突出显示textarea内的文本?是改变文本区域的一部分的背景还是选择文本的一部分?
javascript函数使用.setSelectionRange()选择textarea中的某个单词.在Firefox中,textarea会自动向下滚动以显示所选文本.在Chrome(第14版)中,它没有.有没有办法让Chrome将textarea向下滚动到新选择的文本?jQuery解决方案欢迎.
目前,我正在制作一个简单的应用程序,使用语音合成API说出文本.我想强调说出来的话(粗体).我目前有一个非常基本的实现,使用'onboundary'事件.但是,我想知道是否有更好/更好的方法,因为我的实现基于一些假设.
var words;
var wordIdx;
var text;
var utterance = new SpeechSynthesisUtterance();
utterance.lang = 'en-UK';
utterance.rate = 1;
window.onload = function(){
document.getElementById('textarea').innerText = 'This is a text area. It is used as a simple test to check whether these words are highlighted as they are spoken using the web speech synthesis API (utterance).';
document.getElementById('playbtn').onclick = function(){
text = document.getElementById('textarea').innerText;
words = text.split(' ');
wordIdx = 0;
utterance.text = text;
speechSynthesis.speak(utterance);
}
utterance.onboundary = function(event){
var e = document.getElementById('textarea');
var it …Run Code Online (Sandbox Code Playgroud)