I want to have a sort of editable div like this:

我希望有一个像这样的可编辑div:

<div onClick="this.contentEditable='true';">
lorem ipsum dolor lorem ipsum dolorlorem ipsum dolor
</div>

But it has to be an input field so it's submitted when you submit the form with the input field in it. Does someone knows how I can show the input field just as plain text with a placeholder?

但它必须是一个输入字段,因此当您提交带有输入字段的表单时,它会被提交。有人知道如何将输入字段显示为带占位符的纯文本吗?

5 个解决方案

#1


5

I have made a little fiddle as I'm not 100% sure what you are asking for so I covered a few things. Some have been mentioned already as I was writing this but still lets have a look.

我已经做了一点小提琴,因为我不是100%肯定你所要求的,所以我介绍了一些事情。有人在我写这篇文章的时候已经提到了,但还是让我们来看看。

HTML:

So you can have two things here, textarea and input. We will start with inputs (although they are pretty much the same depending on what you want to do with them)

所以你可以在这里有两件事,textarea和输入。我们将从输入开始(尽管它们几乎相同,具体取决于您要对它们执行的操作)

Input w/ no border:
<input class="noborder" />

Input w/ no border or outline:
<input class="nothing" />

Input w/ no border:
<input class="noborder" placeholder="Placeholder here" />

Moving on to textarea, as you can see we are using the same class's (view below the code) as there is no need to change any CSS for the textarea.

转到textarea,你可以看到我们正在使用相同的类(在代码下面查看),因为不需要为textarea更改任何CSS。

Textarea w/ no border:
<textarea class="noborder"></textarea>

Textarea w/ no border or outline:
<textarea class="nothing"></textarea>

This one uses readonly, it does exactly as it says. If you look at the demo I have linked at the bottom you will see it does not allow you to edit. I very rarely see it so not sure if there is something bad about it but none the less its an option. The second one like one of the inputs above has a placeholder.

这个使用readonly,它完全按照它说。如果您查看我在底部链接的演示,您将看到它不允许您编辑。我很少看到它,所以不确定它是否有什么不好的东西,但它是一个选项。第二个像上面的输入之一有一个占位符。

Textarea w/ readonly:
<textarea class="nothing" readonly>Try edit</textarea>

Textarea w/ readonly:
<textarea class="nothing" placeholder="Placeholder here" readonly></textarea>

CSS:

.noborder {
    border: 0;
}
.nothing {
    border: 0;
    outline: none;
}

DEMO HERE

I hope this helps, good luck!

我希望这有帮助,祝你好运!

更多相关文章

  1. 在用户将'n'粘贴复制到文本字段后,如何更新视图模型?
  2. 在内容可编辑DIV中的选定文本周围包装bb代码
  3. 带有无线电的JavaScript条件字段不起作用
  4. 如何在onchange()事件后调用的方法中将焦点设置为输入字段?
  5. 可编辑div中的文本计数和子字符串
  6. 在Javascript中将下拉字段乘以文本字段
  7. 如何在Python Django中附加数组字段
  8. flask-admin 新增功能关联两张表,关联的表中的字段显示出来是对象
  9. IronPython编辑器 —— FantasyPython雏形的雏形

随机推荐

  1. [置顶] Android官方文档系列(翻译)
  2. 获得Android设备的唯一序列号
  3. Android Xml文件生成,Xml数据格式写入
  4. Android官方DataBinding(三):RecyclerView
  5. Android常见错误处理
  6. Android Studio 导入 GreenDao
  7. 使用PHP开发Android应用程序技术介绍
  8. Android:Designing for Performance
  9. Android(一)Android Eclipse环境搭建
  10. Android_RelativeLayout属性大全