sách gpt4 ăn đã đi

javascript - replaceWith on XML 问题

In lại 作者:数据小太阳 更新时间:2023-10-29 01:52:09 25 4
mua khóa gpt4 giày nike

检查 jQuery 源代码后,我发现我遇到的问题是因为 replaceWithĐiện thoại html对于 XML 文档不存在。是replaceWith不应该处理 XML 文档?

我发现了这个公认的简单解决方法,以防将来有人需要它,它将完成我正在尝试做的事情:

xml.find('b').each(function() {
$(this).replaceWith($('yo')) // this way you can custom taylor the XML based on each node's attributes and such
});

但我还是想知道为什么简单的方法行不通。


我不太了解 jQuery,但这不可行吗?

xml = $.parseXML('hey')
$(xml).find('b').replaceWith('yo')

thay vì xml代表yo它失败并代表 .我做错什么了吗?我正在使用 jQuery 1.6.2。

biên tập:

附带说明一下,如果我尝试使用 replaceWith 的函数版本,像这样:

$(xml).find('b').replaceWith(function() {
return 'yo' // doesn't matter what I return here
})

我收到这个错误:

TypeError: Cannot call method 'replace' of undefined

Chỉnh sửa 2:

replaceAll但是有效,但我需要使用函数版本,所以我不能满足于此:

$('yo').replaceAll($(xml).find('b')) // works

Chỉnh sửa 3:

这也有效:

xml.find('b').replaceWith($('yo')) // but not with the $() around the argument

câu trả lời hay nhất

这看起来像是 replaceWith() 的设计限制或错误。

当我运行时:

$(xml).find('b').replaceWith(function() {
return 'yo';
})

我收到一个 "this[0].innerHTML is undefined" 异常。 See this jsFiddle .

深入 xmlb 节点没有 innerHTML 成员——这有点道理,因为它不是 HTML。 ;)

因此,看起来 replaceWith() 可能并不总是能很好地处理 XML。 Consider reporting a bug .

关于javascript - replaceWith on XML 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6632482/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress