这个怎么见人火狐啊?

nitaiyoucala 2017-05-12 01:50:18
下面代码在ie下面可以,在火狐下不行。怎么兼容啊?


var highlightcolor='#d5f4fe';
var clickcolor='#51b2f6';
function changeto() {

source = event.srcElement;
if (source.tagName == "TR" || source.tagName == "TABLE")
return;
while (source && source.tagName != "TD")
source = source.parentElement;
if (source) source = source.parentElement;
if (source && source.children) cs = source.children;//source.id != "nc" &&
if ("undefined" != typeof cs && cs[1] && cs[1].style.backgroundColor != highlightcolor && cs[1].style.backgroundColor != clickcolor)
for (i = 0; i < cs.length; i++) {
cs[i].style.backgroundColor = highlightcolor;
}
}
function changeback() {
if ((event.fromElement.contains && event.fromElement.contains(event.toElement))
|| (source && source.contains && source.contains(event.toElement))
|| (source && source.id && source.id == "nc"))
return
if (event.toElement != source && "undefined" != typeof cs && cs[1] && cs[1].style.backgroundColor != clickcolor)
for (i = 0; i < cs.length; i++) {
cs[i].style.backgroundColor = "";
}

}
...全文
134 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
天际的海浪 2017-05-12
  • 打赏
  • 举报
回复
一。在FF中 event必须从事件绑定的函数的参数中获取。 obj.onclick = function (event) { event = event || window.event; changeto(event); } 二。在FF中不是用 event.srcElement ,是用event.target 为了兼容可以定成 source = event.target || event.srcElement;
文盲老顾 2017-05-12
  • 打赏
  • 举报
回复
ff 没有 event,在函数的参数里加个e function changeto(e) { source = e?e.target: event.srcElement;

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧