gpt4 book ai didi

jquery - 这些 JQuery 调用相同吗?

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

有人可以告诉我是否是这样:

    $.ajax({
url: 'test.html',
success: function(data) {
alert("Data Loaded: " + data);
}
});

与此相同:

    $.ajax({
url: 'test.html',
success: function(data) {
alert("Data Loaded: " + $(data).html());
}
});

检索此内容时:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>blank page</title>
</head>
<body>
<div id="content">Some content.</div>
</body>
</html>

我问是因为第二个 jquery ajax 调用没有警报。有人可以解释一下为什么两个版本的警报不一样吗?

最佳答案

引用jQuery Documentation for the $-function :

Simple elements without attributes, e.g., "", are created via document.createElement. All other cases are parsed by assigning the string to the .innerHTML property of a div element. The HTML string cannot contain elements that are invalid within a div, such as html, head, body, or title elements.

您不能将完整的 html 页面放入 $ 函数中,只能将 div 元素中有效的元素放入其中。

关于jquery - 这些 JQuery 调用相同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1694690/

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