在 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();
关于jquery - html方法中的根元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4948160/