使用DIV作为输入 [英] Use a DIV as an input
问题描述
对不起,如果这个问题是非常基本的,但我试图回到编程,我坚持这一点。
我想在HTML中将文本输入到< div>
中,但我不希望默认聊天框,它随< input>
一起提供。我只是希望它可以直接打印到< div>
中的某个位置。
我该怎么做? 您可以使用contenteditable属性,如果你不想提交它的价值到服务器,就像这样:
< div contenteditable =true >我是可编辑的。编辑我!< / div>
所以用户可以编辑文本,但不会被发送到服务器,它只是一个客户端不过,如果你需要将值提交给服务器,你必须使用TextArea或Input标签,并通过CSS样式去除边框。说:
< input id =myTexttype =textstyle =border:none; background:transparent;大纲:0;/>
Sorry if this question is very basic, but I'm trying to get back into programming and I'm stuck with this.
I want to have text input into a <div>
in HTML, but I don't want the default chat box that comes with <input>
. I just want it to directly print to a location within the <div>
.
How can I do this?
You can use contenteditable attribute if you don't wanna submit its value to the server, just like this :
<div contenteditable="true">I'm Editable. Edit me!</div>
So that user can edit the text but it's not gonna be sent to the server and it's just a client side stuff.
But if you need to submit the value to the server you have to use TextArea or Input tag and remove the borders by CSS styles. Say :
<input id="myText" type="text" style="border:none; background: transparent; outline: 0;"/>
这篇关于使用DIV作为输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!