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

首頁 > 開發 > JS > 正文

javascript編程起步(第五課)

2024-09-06 12:43:45
字體:
來源:轉載
供稿:網友
鼠標事件(上)

  隨著課程的進行,能跟著下來的人是越來越少了,不知道是不是因為沒有太多的表現,只是死記的東西,大家都沒有興趣啊。其實網頁上

的很多特效,動作大都是用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">
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 芜湖市| 明光市| 定远县| 尖扎县| 唐山市| 吴堡县| 永登县| 渑池县| 河北省| 卢龙县| 肇庆市| 通化市| 西充县| 舒兰市| 武定县| 浦江县| 巨鹿县| 赣榆县| 勐海县| 滦平县| 明水县| 横峰县| 柳江县| 荆州市| 鲁甸县| 清涧县| 余庆县| 榆中县| 若羌县| 昌宁县| 龙南县| 镇江市| 丰宁| 巴林右旗| 成都市| 黄骅市| 南岸区| 抚顺市| 榆中县| 奉化市| 柳州市|