gpt4 book ai didi

javascript - 具有 contentEditable 的 Div 不会使用 Javascript 发布到表单中

转载 作者:可可西里 更新时间:2023-10-31 23:38:28 26 4
gpt4 key购买 nike

好的,所以我有这个 div:

// DESCRIPTION AREA
$body_html .= "<div id='seq-desc-".$seq_id_d."' contenteditable='true' data-text='Det som skal skje...'>";
$body_html .= $seq_desc_d;
$body_html .= "</div>&nbsp;";

和这个文本区域:

$body_html .= "<textarea id='seq-desc-area-".$seq_id_d."' name='deta-".$seq_id_d."' style='display: none;'></textarea></td>";

在我的表单中,我使用以下代码来激活我的 Javascript 代码:

"<form action='planner_seq_save.php' id='save-".$seq_id_d."' name='save-".$seq_id_d."' method='POST' onsubmit='return getContent".$seq_id_d."'>";

getContent 定义如下:

function getContent'.$seq_id_d.'(){
document.getElementById("seq-desc-area-'.$seq_id_d.'").value = document.getElementById("seq-desc-'.$seq_id_d.'").innerHTML;
}

为什么我在使用 POST 时在我的数据库中得到一个空返回值?我使用 $_POST['deta-(the id)'] 来获取我的帖子。

我还使用标准按钮上的代码保存我的表单。这会使 onsubmit 不起作用吗?

onclick='document.forms['save-".$seq_id_d."'].submit();'

一段时间以来一直在努力找出问题所在,我真的需要别人的意见。

更新:

使用 console.log() 我在函数中没有得到任何返回。所以函数没有运行。

可以找到完整代码here

最佳答案

看起来在触发submit() 方法时没有触发submit 事件,因此没有调用onsubmit 处理程序。 See another question for more info .

因此您可以尝试删除 onsubmit 处理程序并从 onclick 的处理程序中触发 getContent 函数:

onclick='submitForm(id)'

function submitForm(id){
getContent(id);

document.forms(id).submit();
}

关于javascript - 具有 contentEditable 的 Div 不会使用 Javascript 发布到表单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34308586/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com