【发布时间】:2017-04-23 15:39:01
【问题描述】:
我的 twig 模板中有一个包含 contenteditable 跨度的表单。我想更改新文本并将其附加到跨度中,因此在提交表单时它包含新文本。
这是我的 html 表单:
<form action="{{ path('change') }}" method="post">
<span name="profil" class="profil" contenteditable="true">{{ prof.libel }}</span>
<button name="change" type="submit">
</button>
</form>
这是我的 jQuery 脚本:
<script>
$(document).ready(function () {
$('span.profil').change(function () {
$text = $(this).text();
$(this).append(document.createTextNode($text));
});
});
</script>
【问题讨论】:
-
您知道您的 HTML 无效吗?您的打开按钮元素缺少右尖括号
-
啊好吧,那是因为我在发布这个问题时删除了一些代码。但在我的项目中,我的代码没有遗漏任何东西。
标签: jquery html contenteditable