我使用arcgis javascript api开发webgis
我想破坏" measurementID"当用户点击" Deactive"按钮,然后使用" Measurement"重新创建节点。按钮。
要销毁节点,我在模块中使用dojo/dom-construct
和destroy方法
但我无法重新创建节点。如何使用dojo工具包重新创建节点?
registry.byId("deactivate").on("click", function() {
domConstruct.destroy("mesurementID")
});
registry.byId("Measurement").on("click", function() {
// Recreate .... !
});

<div id="mesurementID" style="position:absolute; left:50px; top:100px;width: 150px;height: 15px; z-Index:999;border:solid;border-width: 1pt;border-color: black;">
<div id="measurementDiv"></div>
</div>
&#13;
答案 0 :(得分:2)
有多种方法。
以下是一些可能性:
require(["dojo/dom-construct", "dojo/dom-class", "dojo/dom", "dojo/domReady!"], function(domConstruct, domClass, dom) {
//destroy the node using plain javascript:
var removedNode = dom.byId('test').removeChild(dom.byId('test1'));
//and readd it to the page
dom.byId('test').appendChild(removedNode);
//or using domConstruct
domConstruct.destroy(dom.byId('test1'));
//and recreate it
domConstruct.create('div', {
id: 'test1',
innerHTML: 'div with some content'
}, dom.byId('test'));
//or clone it
var clonedNode = dom.byId('test1').cloneNode(true);
domConstruct.destroy(dom.byId('test1'));
//and readd it
dom.byId('test').appendChild(clonedNode);
//but better, make it hidden
domClass.add(dom.byId('test1'), 'hidden');
//and show it
domClass.remove(dom.byId('test1'), 'hidden');
});
.hidden {
display: none;
}
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/resources/dojo.css">
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/tundra/tundra.css">
<div id="test">
<div id="test1">div with some content</div>
</div>