gpt4 book ai didi

javascript - 在服务器上处理 cloneNode

转载 作者:太空宇宙 更新时间:2023-11-04 14:30:47 26 4
gpt4 key购买 nike

我需要在单击“添加”按钮时克隆某个 div。为此,我使用以下代码:-

    function addDetails()
{
var details=document.getElementById('education');
var eachDetail=document.getElementById('fdetails_edu_div');
var newEduDetail = eachDetail.cloneNode(true);
details.appendChild(newEduDetail);
}//end of addDetails function

因此,每次单击“添加”按钮时,名为“fdetails_edu_div”的 div 会一直附加到名为“education”的 div。

现在我想知道如何在服务器上处理所有这些新的、动态添加的 div(包含文本框)(使用 PHP)。

The problem is when I view the source of the page, after the add button has been clicked (and consequently, new divs have been appended), I do not see any HTML corresponding to the newly created divs. So I don't understand when the form (containing all these divs) will be posted how will the PHP on the server get access to these newly, dynamically added, textboxes contained in the div ?

最佳答案

您看不到新创建的 DIV 因为浏览器的 view-source 功能呈现从服务器下载的原始 HTML 文件(在任何 JavaScript 生效之前).如果你想看到你在浏览器中看到的真实 HTML,使用 DomElement innerHTML 属性,或一些 DOM 检查器(Firefox 为 Firebug,opera 为 DragonFly,opera 为 F12互联网浏览器)。
你应该做的是发送一个 AJAX向服务器请求一些新数据已创建的信息,并让服务器生成新的 HTML。这应该在客户端 addDetails 函数上独立发生。
在客户端,如果 AJAX 调用失败,您还应该删除新的 DIV

因为您没有说明页面是如何生成的,所以我无法告诉您 PHP 脚本应该如何处理 AJAX 请求。这取决于您,除非您向我们提供更多详细信息。

关于javascript - 在服务器上处理 cloneNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19208098/

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