问题描述
var x = event.target || event.srcElement;
document.getElementById(x.id).style.left = 200 +px;
document.getElementById(x.id).style.top = 100 +px;
在Chrome浏览器和IE浏览器上运行良好,但在Firefox上无法运行。尝试在谷歌。谷歌说event.srcElement(工作在IE浏览器,但不是在Firefox),所以我已经添加event.target,但仍然无法正常工作。是否有更多的变化,我需要做的工作在Firefox上?顺便说一句,我使用3.5版本的Firefox。
pre $函数up()
{
dragok = false ;
document.onmousemove = null;
var x = event.target || event.srcElement;
document.getElementById(x.id).style.left = 200 +px;
document.getElementById(x.id).style.top = 100 +px;
}
请帮助我使它在Firefox上工作
事件
定义为处理程序的形式参数。 $ b
IE
全局定义, Chrome
它可以工作,但是 Firefox
只是将它定义为一个函数参数。
function up(e){
// ^ ----------------------------------- ------------------ +
if(!e)e = window.event; //< ---需要这个---和this - > - +
dragok = false;
document.onmousemove = null;
var x = e.target || e.srcElement; //< ---和这些
document.getElementById(x.id).style.left = 200 +px;
document.getElementById(x.id).style.top = 100 +px;
}
var x = event.target||event.srcElement;
document.getElementById(x.id).style.left = 200 + "px" ;
document.getElementById(x.id).style.top = 100 + "px" ;
Works fine on google chrome and IE but not on firefox. Tried it on google. google says event.srcElement(works on IE but not on firefox) so i have added event.target but still not working. Is there anymore changes I need to do to work on firefox? By the way Im using 3.5 version of firefox.
function up()
{
dragok = false;
document.onmousemove = null;
var x = event.target||event.srcElement;
document.getElementById(x.id).style.left= 200 + "px" ;
document.getElementById(x.id).style.top= 100 + "px" ;
}
Please help me to make it work on firefox
Make sure you define event
as a formal parameter to the handler.
IE
defines it globally, and Chrome
defines it both in both places, so it works either way, but Firefox
only defines it as a function parameter.
function up( e ) {
// ^-----------------------------------------------------+
if( !e ) e = window.event; // <---needed this --- and this ->--+
dragok = false;
document.onmousemove = null;
var x = e.target||e.srcElement; // <--- and these
document.getElementById(x.id).style.left= 200 + "px" ;
document.getElementById(x.id).style.top= 100 + "px" ;
}
这篇关于event.target不工作在Firefox上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!