在文本输入字段中输入时,打印在div中键入的内容 [英] While typing in a text input field, printing the content typed in a div

查看:114
本文介绍了在文本输入字段中输入时,打印在div中键入的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,里面有一个空框和一个输入文本框。我希望能够在输入框中输入内容并将其打印在空白框中。

I have a website where there is a empty box and a input text box. I want to be able to type something in that input box and have it be printed on the empty box.

<div class='printchatbox'></div>

这是空框和

which is the empty box and

<input type='text' name='fname' class='chatinput'>

这是输入框。

.printchatbox 
    {border-width:thick 10px;border-style: solid; 
    background-color:#fff;
    line-height: 2;color:#6E6A6B;font-size: 14pt;text-align:left;float: middle;
    border: 3px solid #969293;width:40%;}

我如何做到这一点,我将不胜感激。谢谢

If anyone could tell me how to do this I would greatly appreciate it. Thanks

推荐答案

您可以使用 onkeyup 事件

You use the onkeyup event

使用ID进行搜索要容易得多。

Searching with ids is a lot easier. Add ids to your elements as follows:

<div class='printchatbox' id='printchatbox'></div>

<input type='text' name='fname' class='chatinput' id='chatinput'>

JS

var inputBox = document.getElementById('chatinput');

inputBox.onkeyup = function(){
    document.getElementById('printchatbox').innerHTML = inputBox.value;
}

这是现场示例

这篇关于在文本输入字段中输入时,打印在div中键入的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆