最近一段時間因為特殊原因,正在學習 html 相關技術,這個周末應該就可以結束啦。
本來想全屏點擊,響應并且返回位置信息,結果發現不能響應,經過一番搜索,發現
1、可以給 body 添加 width 和 height ,然后點擊就會響應時間;
2、添加方法
document.onmousedown = function(){alert('0');} // 加入這句的話,點擊鼠標就能響應事件
代碼如下:
html:
<body onmousedown="test1(event)" onmousemove="test1(event)" style="background-color: pink;">
<script language="javascript">
</script>
</body>~~~
css:
body {
width: 500px;
height: 400px;
/width: 100%;/
/height: 100%;/ 100%是不能夠顯示的
}~~~
js:
function test1(locati) {
//window.alert("OK!~");
document.writeln('x=' + locati.clientX + " y=" + locati.clientY);
}
// 這些事只需要其中的一個來驗證就可以了
document.onmousedown = function (locati) {
//window.alert('x=' + locati.clientX + " y=" + locati.clientY);
//alert('0'); // 加入這句的話,點擊鼠標就能響應事件
}
document.onmousedown = function(){alert('0');} // 加入這句的話,點擊鼠標就能響應事件
document.onmousemove = function(){document.writeln("逗逗,大,")} //~~~