问题标签 [clonenode]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 从另一个创建 xml 文件时,selfnodes 的结构发生变化
通过在 C# 中通过将节点从源文件克隆到目标文件来从另一个文件创建 xml 文件时,空节点的结构就像<noeud></noeud>
变成<noeud/>
我试过这个:
有什么方法可以保持相同的结构。
javascript - JS 和 HTML - cloneNode() 不工作
下面的代码按预期工作。
CloneNode.js
以下代码也可以正常工作:
或者
但是当我在上面的 HTML 代码中输入换行符时</ul>
,如下所示,我没有得到输出。因此,没有<li>
在网页上添加元素。
HTML 代码中的缩进如何影响输出?或者有什么我错过的吗?
javascript - JavaScript添加元素方法加倍不添加
div
单击按钮时,我正在尝试使用 JavaScript 创建元素的副本。我正在使用该.cloneNode()
方法,但它使结果成倍增加。
页面上最初只有一个元素实例;单击时加倍为 2,但在下一次单击时再次加倍为 4。我需要它单独添加,因此单击-> 3、单击-> 4 等。
我的代码笔是: https ://codepen.io/anon_guy/pen/VMZWWW
HTML:
JS:
angular - 克隆的元素不能在 Angular4 中提交
我有一个模板,其中包含两个字段,例如名称和年龄,需要克隆并附加到同一个容器中。我使用以下代码实现了这一点。
.html 文件
TS文件
但是在提交表单后我没有得到表单值,而且我需要在单击“删除”按钮时删除克隆的元素。
javascript - 克隆节点只有一级
我想克隆一个只有 1 级子节点的节点,所以没有子节点。
如果我有最后一级作为目标
target.parentNode.parentNode.cloneNode(true)
将克隆所有级别,我希望克隆数据-a,包括数据-a1,但数据-a1 没有子级。
是否可以根据深度级别或其属性删除/添加克隆或不克隆的子级(克隆具有或不具有指定属性的唯一子级的父级)?
如果我会有更多深度级别的东西,我会基于属性,而不是使用递归的 parentNode.parentNode。
javascript - elt.cloneNode(true) 是同步的吗?
我需要知道 element.cloneNode(true) 对于 JavaScript 是否可以是异步的。我跑了这样的事情:
我只有一个突变回调,但这当然不能说服我。有没有人有这方面的知识?
javascript - JavaScript - cloneNode 给出不同的结果
我正在尝试使用 cloneNode 在 JavaScript 中提交之前克隆表单。原始表格有一个选定值的答案,但没有克隆的答案。以下是代码。
经过检查,我发现 encryptedForm(克隆形式)对于一个选择元素具有空值,但它存在于形式(原始形式)中。这是为什么?
我在这里做错了吗?
javascript - HTML on Edge
I need to decide between the use of <template>
or just constructing a highly nested element in Javascript using documentFragment
. Using <template>
would be at lot
I need to decide between the use of <template>
or just constructing a highly nested element in Javascript using documentFragment
. Using <template>
would be at lot cleaner, but Edge support is critical and caniuse.com
seems to indicate there's only partial support:
https://caniuse.com/#feat=template
Does not support Document.importNode on templates, nested templates or elements that contain templates.
Does not support Node.cloneNode on templates, nested templates or elements that contain templates.
The issue with this is that I can't test with Edge (not running Windows 10 nor do I have access to a browser testing suite) and I also can't find anything online about it, on MDN or in Microsoft documentation. Not being able to clone the template into the document pretty much means the standard way of using <template>
goes out the window, which doesn't make sense to me because that seems to be the whole point of <template>
.
The only place that claims this is caniuse.com
but I've learned to trust it and it makes me uncertain about what approach to use. Chances are I'll just use documentFragment
to be safe, but I'm wondering if this is an error on caniuse.com
or if there is another sensible way of using <template>
that is obvious and I'm missing it.
two sides pairing of nested set model? from parent perspective
so far i was able to retrieve 3 things the left children,right side children of a parent i've also added a depth limiter.
to best what model i've used look at this Nested Set Model
if you select everything this is what the table looks like my slight modified version from the Nested Set model from the last link
this is my attempted query the problem here is that its pairing two things the right and some weird pair the check is the correct the cross is the wrong one
this is what the tree looks like to visualize the tree pairing
VarToPairfind is the variable only given variable the rest are computed
this is the csv import file to workbench mysql
the table name is nested_category
Updated version
I need to decide between the use of <template>
or just constructing a highly nested element in Javascript using documentFragment
. Using <template>
would be at lot
I need to decide between the use of <template>
or just constructing a highly nested element in Javascript using documentFragment
. Using <template>
would be at lot cleaner, but Edge support is critical and caniuse.com
seems to indicate there's only partial support:
https://caniuse.com/#feat=template
Does not support Document.importNode on templates, nested templates or elements that contain templates.
Does not support Node.cloneNode on templates, nested templates or elements that contain templates.
The issue with this is that I can't test with Edge (not running Windows 10 nor do I have access to a browser testing suite) and I also can't find anything online about it, on MDN or in Microsoft documentation. Not being able to clone the template into the document pretty much means the standard way of using <template>
goes out the window, which doesn't make sense to me because that seems to be the whole point of <template>
.
The only place that claims this is caniuse.com
but I've learned to trust it and it makes me uncertain about what approach to use. Chances are I'll just use documentFragment
to be safe, but I'm wondering if this is an error on caniuse.com
or if there is another sensible way of using <template>
that is obvious and I'm missing it.
two sides pairing of nested set model? from parent perspective
so far i was able to retrieve 3 things the left children,right side children of a parent i've also added a depth limiter. to best what model i've used look at this Nested Set Model if you select everything this is what the table looks like my slight modified version from the Nested Set model from the last link
this is my attempted query the problem here is that its pairing two things the right and some weird pair the check is the correct the cross is the wrong one this is what the tree looks like to visualize the tree pairing
VarToPairfind is the variable only given variable the rest are computed
this is the csv import file to workbench mysql the table name is nested_category
Updated version
getelementsbyclassname - getElementsByClassName 不起作用,但 Id 工作正常
我正在尝试按类名获取一些元素,但它不起作用。但是,如果我更改为通过 ID 获取元素,它可以正常工作。想了解为什么 Class Name 方法不起作用。这是一个 JSFiddle: http: //jsfiddle.net/kXmpY/2681/ 如果我更改为 ID,它可以工作。我错过了什么?
HTML:
JS:
javascript - 在 Internet Explorer 中使用什么来代替 cloneNode()?
以下 JavaScript 函数旨在打开一个新的 HTML 页面并将 div 的内容复制到其中(当然,实际任务比复制更复杂):
标有 (A) / (B) / (C) 的代码部分是替代品;这三个都在 Firefox 中工作。但是,只有 (A) 可以在 Internet Explorer (11.49) 中使用。其他人抛出以下异常:
- (B) HierarchyRequestError
- (C) 不支持接口
尽管问题JavaScript:cloneNode 与 importNode表明“浏览器不强制执行”两者之间的区别cloneNode
,importNode
但我会理解后者的需要,因为源节点和目标节点属于不同的文档(Firefox 不关心)。但是,既然 Internet Explorer在这种情况下importNode
不允许,为什么不支持呢?cloneNode
复制innerHTML
似乎是克隆节点的一种尴尬方式。importNode
Internet Explorer是否有更好的替代方案?(理想情况下,它将独立于浏览器。)