<!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></title>
<script language=javascript src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script language=javascript src="Scripts/JScript.js" type="text/javascript"></script>
</head>
<body>
<table>
<tr>
<td><img src="Images/fuyandong.jpg" class="tooltip" id="id1" /> </td>
<td> <a href="#" title="傅琰东.">傅琰东</a></td>
</tr>
<tr>
<td><img src="Images/chengqiaoen.jpg" class="tooltip" id="id2" /> </td>
<td><a href="#" title="陈乔恩.">陈乔恩 </a></td>
</tr>
<tr>
<td><img src="Images/guojingming.jpg" class="tooltip" id="id3" /></td>
<td><a href="#" title="郭敬明.">郭敬明</a></td>
</tr>
<tr>
<td><img src="Images/caikangyong.jpg" class="tooltip" id="id4" /> </td>
<td><a href="#" title="蔡康永.">蔡康永</a></td>
</tr>
<tr>
<td><img src="Images/xiada.jpg" class="tooltip" id="id5" /> </td>
<td><a href="#" title="夏达.">夏达</a></td>
</tr>
<tr>
<td><img src="Images/fengxiaogang.jpg" class="tooltip" id="id6" /> </td>
<td><a href="#" title="冯小刚.">冯小刚</a></td>
</tr>
</table>
</body>
</html>
/*最新动态超链接文字提示*/
var myName;
var myUrl;
var myRemark;
var myBroadcast;
var myNum;
$(function () {
var x = 100;
var y = 200;
$("img.tooltip").mouseover(function (e) {
this.myId = this.id;
Ajax(this.myId);
var tooltip = "<div id='tooltip'>" + myName + myUrl + "</div>"; //创建 div 元素
$("body").append(tooltip); //把它追加到文档中
$("#tooltip")
.css({
"top": (e.pageY + y) + "px",
"left": (e.pageX + x) + "px",
"background-color": "Red"
}).show("fast"); //设置x坐标和y坐标,并且显示
}).mouseout(function () {
this.id = this.myId;
$("#tooltip").remove(); //移除
}).mousemove(function (e) {
$("#tooltip")
.css({
"top": (e.pageY + y) + "px",
"left": (e.pageX + x) + "px"
});
});
})
$(function Ajax(aId) {
$.ajax({
url: 'WebXml.xml',
type: 'GET',
async: false,
dataType: 'xml',
timeout: 1000,
cache: false,
error: function (xml) {
alert('加载XML文档出错');
},
success: function (xml) {
//建立一个代码片段
var frag = $("<ul/>");
myName = $(xml).find("student[id='" + aId + "']").children("name").text()
myUrl = $(xml).find("student[id='" + aId + "']").children("url").text()
myRemark = $(xml).find("student[id='" + aId + "']").children("date").text()
myBroadcast = $(xml).find("student[id='" + aId + "']").children("broadcast").text()
myNum = $(xml).find("student[id='" + aId + "']").children("num").text()
}
});
});
每次DIV都显示 在冯小刚下面 为什么我写的坐标没用呢 求解
这是我的代码不过和你的差不多
$("a.tooltip").mouseover(function(e) {
var title = this.title;
var href = $(this).attr("href");
var tooltip = "<div id='tip'><img src='" + href + "' alt='产品预览'></img><br/>" + title + "</div>"; $(tooltip).appendTo("body");
$("#tip").css({
"top": e.pageY + "px",
"left": e.pageX + "px",
"display": "block"
});
});
你自己看看吧
路过