weixin_33714884 2016-07-26 20:00 采纳率: 0%
浏览 31

替换“实时”一词

I made a javascript function to find a word in html component and replace it with another word. However, it could do was to insert a button that when clicked invoke the function to replace the words.

I wonder if anyone knows of a way to do this in "run-time" in the case, when you type a word that should be replaced, it be replaced without having to click the button.

Follows the code to find and replace the words:

var texto = document.getElementById("cadastroLaudo:transcript").value;
var novoParagrafo = texto.replace(/novo paragrafo/g, '
');

document.getElementById('cadastroLaudo:transcript').value = novoParagrafo;

My HTML component that will receive the substitution of the word to be found (code below):

<p:inputTextarea id="transcript" name="transcript" rows="8"
        cols="60" placeholder="Ditado para Geração de Laudo Médico"
        value="#{laudoBean.laudo.texto}" />

And the button that calls the javascript function:

<p:commandButton onclick="formatarTextoLaudo()" value="Formatar" />

In summary, the component is a text box when you type "novo paragrafo" is inserted Enter and the word "novo paragrafo" disappears.

It would be something with Ajax?

Tks!

  • 写回答

1条回答 默认 最新

  • weixin_33736048 2016-07-26 20:02
    关注

    I would detect when user press space, then check if the word needs to be replaced

    $('body').keyup(function(e){   
       if(e.keyCode == 32){
           // user has pressed space
           //change word function           
       }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀