可编辑的分部而不是Textarea。(Editable divisions instead of Textarea. input is not getting submitted ! PHP)

如果我使用

<div contentEditable="true" name="content"></div>

而不是Textarea的形式,我无法提交在上面的可编辑部门采取的输入。

我正在使用可编辑部门,因为我想在运行时在输入可编辑部门添加图像。

那么有没有什么办法提交可编辑部门的输入?

我使用PHP作为服务器端语言。

If i use

<div contentEditable="true" name="content"></div>

instead of Textarea in the form i'm not able to submit the input taken in above editable division.

I'm using editable division because i want to add images at run time in the input editable division.

so is there any way to submit an input taken in editable division??

I'm using PHP as server side language.

最满意答案

只有输入元素的值使用表单提交。

提交表单时,请使用客户端上的脚本将div的内容放入隐藏字段中。

例如:

<form action="/blah.php" method="post" onsubmit="prepForm()"> <div contentEditable="true" id="editor"></div> <input type="hidden" name="content" id="content"> </form>

...

<script> function prepForm() { document.getElementById('content').value = document.getElementById('editor').innerHTML; } </script>

Only the values of input elements get submitted with a form.

Use a script on the client to put the contents of the div into a hidden field when the form is submitted.

For example:

<form action="/blah.php" method="post" onsubmit="prepForm()"> <div contentEditable="true" id="editor"></div> <input type="hidden" name="content" id="content"> </form>

...

<script> function prepForm() { document.getElementById('content').value = document.getElementById('editor').innerHTML; } </script>

更多推荐