我以前使用过这个并且定位 div 没有问题,但这次我的目标是隐藏在一个已经在 Intranet 站点上很长时间的表中的图像。我终于找到了它的代码,并在名为$('.targetTable')
. 现在我正在尝试从表格中提取某些元素以显示在我的新页面上的 div 中。下面是从表格中提取 HTML 的代码:
$(document).ready(function(){
$mission = $('#targetDiv');
$.ajax({
url: "http://example.com/values/values.cfm?val=commitment",
cache: false
}).done(function( html ) {
$div = $('table.targetTable', html);
$img = $div.children('tr:eq(3)').children('td').find('img').attr('src');
$mission.append('<img src="'+$img+'" />');
});
});
这是由 AJAX 调用提取的表:
<!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>commitment</title>
</head>
<body>
<table border="0" style="border: 1px solid gray;" cellspacing="0" class="targetTable">
<tr style="background-color: #FFDDBB;">
<td align="center" style="padding: 8px;">
<img src="../mp_images/values/commitment_med.jpg" width="600" height="439">
</td>
</tr>
<tr style="background-color: #FFDDBB;">
<td valign="top" style="padding: 8px;">
<div style="text-align:center; letter-spacing: 4px; font-size: 140%; font-weight: bold; margin-bottom: 30px;">COMMITMENT</div>
<div style="font-family:Georgia, 'Times New Roman', Times, serif; font-size: 100%">
We recognize Commitment as a fundamental cornerstone underpinning our everyday activities. Our commitment is a steadfast devotion to our people, our licensees, and to the public to responsibly carry out the mission of the agency, unwavering from the highest standards of safety, excellence, and professionalism.
</div>
</td>
</tr>
<tr style="background-color: #FFDDBB;">
<td style="border-bottom: 1px solid gray;">
</td>
</tr>
<tr bgcolor="white">
<td align="center" colspan="3" style="padding: 8px;">
<a href="../values/values.cfm?val=Commitment" ><img src="../mp_images/values/commitment_small.jpg" border="0" /></a>
<a href="../values/values.cfm?val=Cooperation"><img src="../mp_images/values/cooperation_small.jpg" border="0" /></a>
<a href="../values/values.cfm?val=Excellence"><img src="../mp_images/values/excellence_small.jpg" border="0" /></a>
<a href="../values/values.cfm?val=Integrity"><img src="../mp_images/values/integrity_small.jpg" border="0" /></a>
<a href="../values/values.cfm?val=Openness"><img src="../mp_images/values/openness_small.jpg" border="0" /></a>
<a href="../values/values.cfm?val=Respect"><img src="../mp_images/values/respect_small.jpg" border="0" /></a>
<a href="../values/values.cfm?val=Service"><img src="../mp_images/values/service_small.jpg" border="0" /></a>
<a href="../values/values.cfm?val=Mission"><img src="../mp_images/values/Mission_small.jpg" border="0" /></a>
<a href="../values/values.cfm?val=Vision"><img src="../mp_images/values/Vision_small.jpg" border="0" /></a>
</td>
</tr>
</table>
</body>
</html>
现在,每次我以 img src 为目标时,它都会以未定义的形式返回。我的目标是错误的还是其他类似 doctype 或 CFM 兼容性的东西?同样出于某种原因,我无法弄清楚 Chrome 会引发错误。它告诉我,我的 AJAX 已将 HTML 中的所有相对路径转换为绝对路径,但绝对路径指向我的页面而不是旧页面和图像位置。如果有人能弄清楚这一点,我会给你指出我之前问过这个问题的页面,你会得到一个双重复选标记。