【发布时间】:2016-02-17 20:54:42
【问题描述】:
我的问题是在删除现有超链接后,我无法将新的超链接附加到 div 中。
这里我检查 div 内是否有任何超链接,如果有,我将其全部删除。
var node = document.getElementById('nearByCitiesDiv');
while (node.hasChildNodes()) {
node.removeChild(node.lastChild);
}
然后我创建了新的超链接,但它们不会显示在 div 中。 顺便说一句,我正在使用 jquery 移动面板。如果我不删除 div 的 childNodes,下面的代码也可以正常工作并在 div 内添加新的超链接。
var element = $('<a data-role="button" style="text-decoration:none;" href="#/" onclick="showNearCityWeather(' + nearbyPosition.lat + ',' + nearbyPosition.lng + ')" data-theme="a">' + c.toponymName + '</a >');
$("#nearByCitiesDiv").controlgroup("container")["append"](element);
$("#nearByCitiesDiv").controlgroup("refresh");
$('[data-role="button"]').button();
【问题讨论】:
标签: jquery-mobile appendchild removechild