[求助]js定义alt或title样式问题.
以下代码没有样式定义。欲实现的效果:点击链接时弹出的提示框有彩色框或背景色,应怎样修改,谢谢!function initRange()
{
var maplist = document.all.tags("MAP");
if(maplist != null)
{
for(var i=0;i<maplist.length;i++)
{
var mapobj = maplist.item(i);
//alert(mapobj.id);
mapobj.onmouseover = drawLine;
mapobj.onmouseout = MouseOutMap;
//mapobj.onclick = clickmap;
}
}
}
/* 坐标模式 */
function drawLine()
{
//alert("hi");
var areaObj = event.srcElement;
var str = areaObj.coords;
var arr = str.split(",");
var xArr = new Array(arr.length/2);
var yArr = new Array(arr.length/2);
var x=0,y=0;
var max =1,min =2;
for (var t =0 ;t<arr.length ;t=t+2 )
{
//alert("x == "+arr[t]);
xArr[x++] = parseInt(arr[t]);
}
for (var t =1 ;t<arr.length ;t=t+2 )
{
//alert("y == "+arr[t]);
yArr[y++] = parseInt(arr[t]);
}
var x1 = find(xArr,min);
//alert("x min == "+x1);
var x2 = find(xArr,max);
//alert("x max == "+x2);
var y1 = find(yArr,min);
//alert("y min == "+y1);
var y2 = find(yArr,max);
//alert("y max == "+y2);
var mapObj = areaObj.parentElement;
if(typeof mapObj == "object")
{
//alert(mapObj.name);
var imgs = document.all.tags("img");
//alert(imgs.length);
if(imgs != null)
{
for(var i=0;i<imgs.length;i++)
{
var imgobj = imgs.item(i);
//alert(imgobj.src);
var mapname = imgobj.useMap;
//alert(mapname);
if(typeof mapname == "string" && mapname.toLowerCase() == ("#" + mapObj.name).toLowerCase())
{
//alert(mapname);
var imgleft = 0;
var imgtop = 0;
var imgparent = imgobj.parentElement;
while(typeof imgparent == "object" && imgparent.tagName.toUpperCase() != "BODY")
{
imgleft += imgparent.offsetLeft - imgparent.style.borderLeft;
imgtop += imgparent.offsetTop - imgparent.style.borderTop;
imgparent = imgparent.parentElement;
}
imgleft = imgleft + 23;
imgtop = imgtop + 12;
//alert("left1 == "+imgleft);
//alert("top1 == "+imgtop);
MouseOverMap(x1,y1,x2,y2,imgleft,imgtop);
}
}
}
}
}
function find(arr,type)
{
var tmp=arr[0];
if (type==1)
{
for (var loop=0;loop<arr.length ;loop++ )
if (arr[loop]>tmp)
tmp = arr[loop];
return tmp;
}
else if (type == 2)
{
for (var loop=0;loop<arr.length ;loop++ )
if (arr[loop]<tmp)
tmp = arr[loop];
return tmp;
}
}
function MouseOverMap(x1,y1,x2,y2,imgleft,imgtop) {
var divElm = document.getElementById("leveldiv");
var Left = 0 + x1;
var Top = 0+ y1;
var Right = parseInt(x2 - x1);
var bottom = parseInt(y2 - y1);
divElm.style.border = "solid 2px #FF0000";
divElm.style.left = Left+imgleft-20;
divElm.style.top = Top+imgtop-8;
divElm.style.width = Right+6;
divElm.style.height = bottom+6;
divElm.style.cursor = "pointer";
}
function MouseOutMap() {
var divElm = document.getElementById("leveldiv");
divElm.style.border = "";
}
function clickmap()
{
if(typeof event.srcElement != "object")
return;
var obj = event.srcElement;
//window.open(obj.href,"newwin","toolbar=no,resizable=no,scrollbars=yes,dependent=no,width=700,height=500");
//obj.target="_blank";
}
{
var maplist = document.all.tags("MAP");
if(maplist != null)
{
for(var i=0;i<maplist.length;i++)
{
var mapobj = maplist.item(i);
//alert(mapobj.id);
mapobj.onmouseover = drawLine;
mapobj.onmouseout = MouseOutMap;
//mapobj.onclick = clickmap;
}
}
}
/* 坐标模式 */
function drawLine()
{
//alert("hi");
var areaObj = event.srcElement;
var str = areaObj.coords;
var arr = str.split(",");
var xArr = new Array(arr.length/2);
var yArr = new Array(arr.length/2);
var x=0,y=0;
var max =1,min =2;
for (var t =0 ;t<arr.length ;t=t+2 )
{
//alert("x == "+arr[t]);
xArr[x++] = parseInt(arr[t]);
}
for (var t =1 ;t<arr.length ;t=t+2 )
{
//alert("y == "+arr[t]);
yArr[y++] = parseInt(arr[t]);
}
var x1 = find(xArr,min);
//alert("x min == "+x1);
var x2 = find(xArr,max);
//alert("x max == "+x2);
var y1 = find(yArr,min);
//alert("y min == "+y1);
var y2 = find(yArr,max);
//alert("y max == "+y2);
var mapObj = areaObj.parentElement;
if(typeof mapObj == "object")
{
//alert(mapObj.name);
var imgs = document.all.tags("img");
//alert(imgs.length);
if(imgs != null)
{
for(var i=0;i<imgs.length;i++)
{
var imgobj = imgs.item(i);
//alert(imgobj.src);
var mapname = imgobj.useMap;
//alert(mapname);
if(typeof mapname == "string" && mapname.toLowerCase() == ("#" + mapObj.name).toLowerCase())
{
//alert(mapname);
var imgleft = 0;
var imgtop = 0;
var imgparent = imgobj.parentElement;
while(typeof imgparent == "object" && imgparent.tagName.toUpperCase() != "BODY")
{
imgleft += imgparent.offsetLeft - imgparent.style.borderLeft;
imgtop += imgparent.offsetTop - imgparent.style.borderTop;
imgparent = imgparent.parentElement;
}
imgleft = imgleft + 23;
imgtop = imgtop + 12;
//alert("left1 == "+imgleft);
//alert("top1 == "+imgtop);
MouseOverMap(x1,y1,x2,y2,imgleft,imgtop);
}
}
}
}
}
function find(arr,type)
{
var tmp=arr[0];
if (type==1)
{
for (var loop=0;loop<arr.length ;loop++ )
if (arr[loop]>tmp)
tmp = arr[loop];
return tmp;
}
else if (type == 2)
{
for (var loop=0;loop<arr.length ;loop++ )
if (arr[loop]<tmp)
tmp = arr[loop];
return tmp;
}
}
function MouseOverMap(x1,y1,x2,y2,imgleft,imgtop) {
var divElm = document.getElementById("leveldiv");
var Left = 0 + x1;
var Top = 0+ y1;
var Right = parseInt(x2 - x1);
var bottom = parseInt(y2 - y1);
divElm.style.border = "solid 2px #FF0000";
divElm.style.left = Left+imgleft-20;
divElm.style.top = Top+imgtop-8;
divElm.style.width = Right+6;
divElm.style.height = bottom+6;
divElm.style.cursor = "pointer";
}
function MouseOutMap() {
var divElm = document.getElementById("leveldiv");
divElm.style.border = "";
}
function clickmap()
{
if(typeof event.srcElement != "object")
return;
var obj = event.srcElement;
//window.open(obj.href,"newwin","toolbar=no,resizable=no,scrollbars=yes,dependent=no,width=700,height=500");
//obj.target="_blank";
}
[ 本帖最后由 thbwn 于 2010-4-11 17:04 编辑 ]