In fact, obtaining the mouse position is just one sentence, but if you don't know the difference between browsers, the whole process will be depressing. The difference is as follows:
1. for IE, the distance between x and y axes is obtained using event. x and event. y respectively;
Use event. pageX and event. pageY to obtain the distance between x and y axes in FF;
2. the position obtained by using this method in IE is not the position where the scroll bar has been rolled, that is, it will only be counted on the edge of the browser;
FF will calculate the locations that have been rolled in;
(This place breaks down me very much. For this little difference, I have rewritten all the programs I have used and killed them ......)
Solution 1 is nothing more than determining the browser and the method used;
Solution 2 is to add document.documentelement.scrolltopand document.doc umentElement. scrollLeft In the case of Internet Explorer;
I know little about JS. If you have better suggestions, please leave a message! Thank you.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional. dtd "> <ptml xmlns =" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv =" Content-Type "content =" text/html; charset = gb2312 "/> <title> JS obtains the modified version of the script home for the mouse location (compatible with multiple Browser IE and firefox) </title> </pead> <body> mouse X axis: <input id = xxx type = text> Y axis of the mouse: <input id = yyy type = text> </body>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]