如何获取价值的内容可以在PHP中编辑 [英] How to get value contentEditable in PHP
问题描述
例如我有这个代码,想要在PHP中的变量中获取它的值:
< div contentEditable =true>在这里输入
< img src =http://t2.gstatic.com/images?q=tbn:ANd9GcQCze-mfukcuvzKk7Ilj2zQ0CS6PbOkq7ZhRInnNd1Yz3TQzU4e&t=1/>< / div>
因为我想使用这个作为html正文的电子邮件。 >
Infact我想获取contentEditable的值并将其保存到变量中,然后将该变量用作我的电子邮件的正文。任何想法如何执行此任务。
您需要将元素的内容存储在表单元素中,以便它可以提交到您的PHP页面。
我假设你想要 contenteditable
而不是 textarea
为富文本...考虑看看所见即所得编辑器,如 TinyMCE 。
如果您仍然希望使用当前的方法,则需要一些JS将div的值在页面提交之前复制到隐藏的表单元素中。
HTML
< div id =emailcontentcontenteditable> asdf< / div>
< form>
< input type =textid =aname =a/>
< input type =submitname =submitid =submit/>
< / form>
$(#submit)点击(function(){
$(#a)。val ($(#emailcontent)。html());
});
How we can get the content present in contentEditable in html format in PHP
For example i have this code and want to get its value in a variable in PHP:
<div contentEditable="true"> type here
<img src="http://t2.gstatic.com/images?q=tbn:ANd9GcQCze-mfukcuvzKk7Ilj2zQ0CS6PbOkq7ZhRInnNd1Yz3TQzU4e&t=1" /></div>
because i want to use this as html body for an email.
Infact i want to get the value of contentEditable and save it into a variable and then use that variable as a body for my email. Any idea how to perform this task.
You'll need to store the contents of the element in a form element so it can be submitted to your PHP page.
I assume you want contenteditable
instead of textarea
for rich text... consider taking a look at WYSIWYG editors like TinyMCE instead.
If you still want to stick with your current method, you'll need some JS to copy the value of the div into a hidden form element before the page gets submitted.
HTML
<div id="emailcontent" contenteditable>asdf</div>
<form>
<input type="text" id="a" name="a"/>
<input type="submit" name="submit" id="submit" />
</form>
$("#submit").click(function() {
$("#a").val($("#emailcontent").html());
});
这篇关于如何获取价值的内容可以在PHP中编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!