将文本值输入div? [英] Input text value into a div?

查看:102
本文介绍了将文本值输入div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这个文本框:

<input type="text" id="myText" placeholder="Enter Name Here">

按下按钮后,我想将输入的值发送到此div中:

Upon pressing a button, I would like to send the value entered into this div:

<div id="text2"></div>

我不完全确定如何做到这一点。我是否创建了一个函数并将其调用到div?我该怎么办?

I'm not entirely sure how to do this. Do I create a function and call it to the div? How would I do that?

有人可以为我清理这个吗?谢谢。

Could someone clear this up for me? Thanks.

推荐答案

在按钮上添加一个onclick:

Add an onclick to your button:

<input type="button" id="somebutton" onclick="addText()">

然后写下javascript:

Then write the javascript:

function addText()
{
    document.getElementById('text2').innerHTML = document.getElementById('myText').value;
}

这篇关于将文本值输入div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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