gpt4 book ai didi

jquery - html方法中的根元素

转载 作者:行者123 更新时间:2023-12-01 08:24:31 24 4
gpt4 key购买 nike

在 jQuery .html() 方法中,不知何故不返回根元素,例如:

var test = $('<root><val>hello world</val></root>');
var str = test.html(); // '<val>hello world</val>'

如何获取包含根标签的字符串?

最佳答案

您需要 outerHTML 属性。 Firefox 不支持它,因此您需要修复:

var str = test[0].outerHTML || $('<div>').append(test).html();

工作示例: http://jsfiddle.net/Ub244/

关于jquery - html方法中的根元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4948160/

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