gpt4 book ai didi

javascript - 引用多个div的ajax调用

转载 作者:行者123 更新时间:2023-12-03 11:07:09 26 4
gpt4 key购买 nike

我在jquery mobile中有两个页面,每个页面都有一个名为contentdiv,在div内部我通过ajax调用外部页面。 。对于 "page1" ,调用工作正常,但对于 "page2" ,调用不起作用。尽管“page2”中的 div 与 “page1” 具有相同的名称。

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>


<script language="javascript">

$(document).ready(function() {
$.ajaxSetup({ cache: false });
setInterval(function() {
$('#content').load('total.asp');
}, 3000);
});

</script>

</head>

<body>
<div data-role="page" id="page1">
<div data-role="header">
<h1>Page 1</h1>
</div>
<div data-role="content">
<table width="311" border="0" cellpadding="3" cellspacing="3">
<tr>
<td width="77">Content</td>
<td width="102"><div id="content"></div></td>
<td width="102"><a href="#page2">Go to Page 2</a></td>
</tr>
</table>
</div>
<div data-role="footer">
<h4>Footer</h4>
</div>
</div>
<p>&nbsp;
<div data-role="page" id="page2">
<div data-role="header">
<h1>Page 2</h1>
</div>
<div data-role="content">
<table width="320" border="0" cellpadding="3" cellspacing="3">
<tr>
<td width="77">Content</td>
<td width="102"><div id="content"></div></td>
<td width="102"><a href="#page1">Go to Page 1</a></td>
</tr>
</table>
</div>
<div data-role="footer">
<h4>Footer</h4>
</div>
</div>
</p>
</body>
</html>

最佳答案

尝试使用:

$("div").find("[data-role='content']").load('total.asp');

因为您已将其作为数据属性给出。如果你有多个同名的 id,你可以更好地使用类,在这种情况下它将是:

$(".content").load('total.asp');

关于javascript - 引用多个div的ajax调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27792145/

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