如何使用 php 在 td 中发送 contenteditable 值
How to send contenteditable value in td with php
我的页面中有以下代码:
echo "<td style='border-bottom:1px solid #FFA500;' contenteditable='true'>".$result['body']."</td>";
并且我想将编辑好的内容发送到mysql_query。
我只需要将 id 添加到 <td>
并使用 ajax 吗??
编辑:
请检查以下问题以获取更多信息、参考和有用的答案:
How to save and retrieve contenteditable data
是的,您必须使用 AJAX 来存储编辑的内容,或者使用生成(隐藏)输入字段并提交包含编辑内容的表单的脚本值。
在此处了解有关 contenteditable 的更多信息(特别是 'Storing the changes'):
http://html5doctor.com/the-contenteditable-attribute/#storing-changes
它为您提供了一个 JS Bin code snippet,其中显示了如何使用 jQuery 的 $.ajax 将数据发送到服务器的示例。
但是,它是在 keydown 事件上执行的,为了保存请求,我建议在 blur.
上执行
是的,你应该使用 Ajax。如果你想"live update"它,当contenteditable
变化时使用input
事件来监听;或者创建一个按钮,如果你想保存你的值 "when they're done"。
我的页面中有以下代码:
echo "<td style='border-bottom:1px solid #FFA500;' contenteditable='true'>".$result['body']."</td>";
并且我想将编辑好的内容发送到mysql_query。
我只需要将 id 添加到 <td>
并使用 ajax 吗??
编辑: 请检查以下问题以获取更多信息、参考和有用的答案: How to save and retrieve contenteditable data
是的,您必须使用 AJAX 来存储编辑的内容,或者使用生成(隐藏)输入字段并提交包含编辑内容的表单的脚本值。
在此处了解有关 contenteditable 的更多信息(特别是 'Storing the changes'): http://html5doctor.com/the-contenteditable-attribute/#storing-changes
它为您提供了一个 JS Bin code snippet,其中显示了如何使用 jQuery 的 $.ajax 将数据发送到服务器的示例。 但是,它是在 keydown 事件上执行的,为了保存请求,我建议在 blur.
上执行是的,你应该使用 Ajax。如果你想"live update"它,当contenteditable
变化时使用input
事件来监听;或者创建一个按钮,如果你想保存你的值 "when they're done"。