在下面的代碼,渲染鼠標位置使用document.write對象
<script>
var mie = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
if(!mie){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = mousePos;
var mouseX = 0;
var mouseY = 0;
function mousePos(e){
if(!mie){
mouseX = e.pageX;
mouseY = e.pageY;
}
else{
mouseX = e.clientX + document.body.scrollLeft;
mouseY = e.clientY + document.body.scrollRight;
}
/*document.formex.mousex.value = mouseX;
document.formex.mousey.value = mouseY;*/
document.write("X: " + mouseX + ";Y: " + mouseY + "; Time: " + new Date());
return true;
}
</script>
期望輸出是呈現用於在移動每鼠標位置的每個新條目。
我只能使用document.write
對象呈現一個鼠標位置。有更好的方法來渲染嗎?
使用'console.log' :) – HTDE
http://codepen.io/anon/pen/GoopvW?editors = 001 – HTDE