国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

javascript編程起步(第五課)

2024-09-06 12:43:19
字體:
來源:轉載
供稿:網友
鼠標事件(上)
隨著課程的進行,能跟著下來的人是越來越少了,不知道是不是因為沒有太多的表現,只是死記的東西,大家都沒有興趣啊。其實網頁上
的很多特效,動作大都是用javascript來實現的,沒有javascript的網頁,就象一個人沒有了肌肉一樣。但是所有的動作都是有函數來控制的
,而控制語句是基礎中的基礎。希望大家能耐心的學下去。今天的課程就輕松一下,學習點能見到效果的。
主要內容就是基于鼠標的事件,有如下幾種:
1.mouseover(鼠標移至)
2.mouseout(鼠標移出)
3.mousemove(鼠標移動)
4.mousedown(鼠標按下)
5.mouseup(鼠標彈起)
6.click(單擊)
7.dblclick(雙擊)
通常1和2組合起來使用,當用戶把鼠標移動到一個超鏈接或者其他元素時,mouseover事件就會發生,mouseout總會伴隨著它,因為當鼠標
離開時,mouseout事件就會發生。
例子:
<html>
<head>
<title>test</title>
<script language="javascript">
function text_onmouseover(){
mytext.style.fontSize="30pt";
mytext.style.color="red";
mytext.style.fontStyle="italic";
}
function text_onmouseout(){
mytext.style.fontSize="20pt";
mytext.style.color="blue";
mytext.style.fontStyle="normal";
}
</script>
</head>
<body>
<p id=mytext onmouseover="text_onmouseover()"
onmouseout="text_onmouseout()">http://www.javascript.com.cn</p>
<p>看看字體樣式有什么變化</p>
</body>
</html>
這里定義了兩個函數,來使字體改變樣式。關于函數我們以后會詳細的講解。
(注意:ie對頁面上的所有元素都支持mouseover和mouseout事件,但對于netscape navigator來說,只有超鏈接和層支持這兩個事件。)
下面看鼠標移動的例子:
<html>
<body onMousemove="micro$oftMouseMove()">
<SCRIPT LANGUAGE="JavaScript">
if (navigator.appName == ’Netscape’)
{
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = netscapeMouseMove;
}
function netscapeMouseMove(e) {
if (e.screenX != document.test.x.value && e.screenY != document.test.y.value)
{
document.test.x.value = e.screenX;
document.test.y.value = e.screenY;
}
}
function micro$oftMouseMove() {
if (window.event.x != document.test.x.value && window.event.y !=
document.test.y.value)
{
document.test.x.value = window.event.x;
document.test.y.value = window.event.y;
}
}
</SCRIPT>
<FORM NAME="test">
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 荔浦县| 邵阳市| 木兰县| 新巴尔虎右旗| 建水县| 彭泽县| 满城县| 新河县| 旅游| 桃源县| 柏乡县| 茂名市| 牙克石市| 阿瓦提县| 博乐市| 藁城市| 耒阳市| 梁河县| 田东县| 乐亭县| 宁南县| 洛宁县| 舒兰市| 磐石市| 定日县| 交城县| 宁河县| 邵阳市| 宾川县| 永和县| 株洲县| 靖边县| 武乡县| 徐汇区| 万载县| 缙云县| 察哈| 醴陵市| 康马县| 阿瓦提县| 平邑县|