第2个回答 2010-09-24
window.onload=initAll;// 网页加载执行
var xhr=null;
var xPos,uPos;
function initAll(){
var allLinks=document.getElementsByTagName("a");
for(var i=0;i<allLinks.length;i++){
allLinks[i].onmouseover=showPreview;
allLinks[i].onmouseout=hidePreview;
}
}
function showPreview(evt){ //事件处理;
getPreview(evt);
return false;
}
function hidePreview(){
document.getElementById("previewWin").style.visibility="hidden";
}
function getPreview(evt){
if(evt){
var url=evt.target;
}
else {
evt=window.event;
var url=evt.srcElement;
}
xPos=evt.clientX;
yPos=evt.clientY;
if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}
else{
if(window.ActiveXObject){
try{
xhr=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
}
}
}
if(xhr){
xhr.onreadystatechange=showContents;
xhr.open("GET",url,true);
xhr.send();
}
else{
alert("Sorry,but i can't create an XMLHttpRequest");
}
}
function showContents(){
var prevWin=document.getElementById("previewWin");
if(xhr.readyState==4){
if(xhr.status==200){
prevWin.innerHTML=xhr.responseText;
}
else{
prevWin.innerHTML="there was a problem with the request"+xhr.status;
}
prevWin.style.top=parseInt(yPos)+2+"px";
prevWin.style.left=parseInt(xPos)+2+"px";
prevWin.style.visibility="visible";
prevWin.onmouseout=hidePreview;
}
}
我给你的这段代码 是ajax 技术实现链接预览的。你只要稍微修改一下,就可以用了。xmlhttpRequset返回网页本文,你把你要的数据过滤掉拿下来,再在你 的网页上利用innerHTML输出来就ok了。。。
你现在要做的就是看懂这段代码,稍微了解一下ajax技术。不懂可以问我。