请问如何获取一个超链接的背景颜色? 请问如何获取一个超链接的背景颜色?或者是如果判断 超链接背景色和超链接本身的颜色是否一样? 比如背景色是白色,超链接也是白色,那么如何用js去检测它们?请高人指教? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!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=gb2312" /><title>无标题文档</title><style type="text/css">a{background-color:#00FF00;color:#0000FF;}</style><script type="text/javascript"> function getStyle(obj){ var style=""; if(document.defaultView&&document.defaultView.getComputedStyle){ style=document.defaultView.getComputedStyle(obj);; }else{ style=obj.currentStyle; } return style; } function init(){ var as=document.getElementsByTagName("a")[0]; as.onclick=function(e){ var style=getStyle(this); alert(style.backgroundColor+":"+style.color); var a=e||window.event; if(a.preventDefault){ a.preventDefault(); }else{ a.returnValue=false; } } } window.onload=init;</script></head><body><a href="">ss</a></body></html>大体这样试试 firefox上怎样实现pasteHTML()的功能? js模拟多线程(setTimeout)问题 radio后面的输入框验证 js调用ocx的方法,有输出参数 请教个正则表达式 checkbox复选框的值传递问题 窗口属性的控制。 javascript屬性函數方法已經整理出來了 , 歡迎來文檔中心 大神帮忙看下 金额统计的效果~ 关于《JS的数据结构与算法》中的迭代器始终会死循环? js 键盘事件 【求助】怎么把json的数据以string的方式读取出来,用ajax?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
a{
background-color:#00FF00;
color:#0000FF;
}
</style>
<script type="text/javascript">
function getStyle(obj){
var style="";
if(document.defaultView&&document.defaultView.getComputedStyle){
style=document.defaultView.getComputedStyle(obj);;
}else{
style=obj.currentStyle;
}
return style;
}
function init(){
var as=document.getElementsByTagName("a")[0];
as.onclick=function(e){
var style=getStyle(this);
alert(style.backgroundColor+":"+style.color);
var a=e||window.event;
if(a.preventDefault){
a.preventDefault();
}else{
a.returnValue=false;
}
}
}
window.onload=init;
</script>
</head><body>
<a href="">ss</a>
</body>
</html>
大体这样试试