gpt4 book ai didi

javascript - 使用 jQuery 编写 XML 文件

转载 作者:数据小太阳 更新时间:2023-10-29 02:00:59 25 4
gpt4 key购买 nike

通过 jquery 更改 xml 属性很容易,只需:

$(this).attr('name', 'hello');

但是我怎样才能在文件中添加另一个标签呢?我尝试使用 append JS 静静地死去。

有什么办法吗?

说明:此代码是 firefox 扩展的一部分,因此不必担心保存到用户文件系统中的问题。仍然附加不适用于 xml 文档,但我可以更改 xml 属性值

最佳答案

问题是 jQuery 正在网页的当前 文档 中创建新节点,因此节点无法附加到不同的 XML 文档。因此必须在 XML 文档中创建节点。

你可以这样做

var xml = $('<?xml version="1.0"?><foo><bar></bar><bar></bar></foo>'); // Your xml
var xmlCont = $('<xml>'); // You create a XML container
xmlCont.append(xml); // You append your XML to the Container created in the main document

// Now you can append without problems to you xml
xmlCont.find('foo bar:first').append('<div />');

xmlCont.find('foo bar div'); // Test so you can see it works

关于javascript - 使用 jQuery 编写 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1086655/

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