处理服务器上的cloneNode [英] handling cloneNode on the server

查看:109
本文介绍了处理服务器上的cloneNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击添加按钮时,需要克隆某个div。要实现这一点,我使用以下代码: -

  function addDetails()
{
var details =的document.getElementById( '教育');
var eachDetail = document.getElementById('fdetails_edu_div');
var newEduDetail = eachDetail.cloneNode(true);
details.appendChild(newEduDetail);
} // addDetails函数的结尾

所以名为'fdetails_edu_div'的div保持每次点击添加按钮时,将其附加到名为教育的div。



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


问题是当我查看页面的源代码,在添加按钮被点击之后(因此,新的div被附加了),我没有看到与新创建的div相对应的任何HTML。所以我不明白什么时候的表单(包含所有这些div)将被发布在服务器上的PHP将如何访问这些新的,动态添加的文本框包含在div?


< blockquote>

解决方案

你看不到新创建的 DIV s beaceuse浏览器 view-source 函数呈现从服务器下载的原始HTML文件(在任何JavaScript发生效果之前)。如果要在浏览器中看到真正的HTML,请使用DomElement innerHTML 属性或某些DOM检查器( DragonFly 的com,=nofollow> Firebug ,在互联网浏览器中 F12 )。

您应该做的是向服务器发送 AJAX 请求一些新数据被创建并使服务器生成新的HTML的信息。这应该在客户端 addDetails 函数上独立发生。

在客户端,您还应该删除新的 DIV 如果AJAX调用失败。



因为你没有说明页面的生成方式,我可以给你没有线索,PHP脚本如何处理AJAX请求。这取决于您,除非您向我们提供更多详细信息。


I need that when I click on the 'add' button a certain div should be cloned. To achieve this I am using the following code : -

    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

so the div named, 'fdetails_edu_div', keeps getting appended to the div named, 'education' every time the 'add' button is clicked.

Now I want to know how can I handle all of these new, dynamically added, divs (that contain text boxes) on the server (using 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 ?

解决方案

You cannot see the newly created DIVs beaceuse browser view-source function renders the original HTML file that was downloaded from the server (before any JavaScript has taken an effect). If you want to see the real HTML as you see it in the browser, use the DomElement innerHTML property, or some DOM inspector (Firebug for Firefox, DragonFly in opera, F12 in internet explorer).
What you should do is to send an AJAX request to the server with the information that some new data were created and have the server generate the new HTML. This should happen independently on the client addDetails function.
On the client side, you also should remove the new DIV if the AJAX call fails.

Because you didn't state how the page is generated, I can give you no leads how should the PHP script handle the AJAX requests. This is up to you unless you provide us with more details.

这篇关于处理服务器上的cloneNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆