javascript學習筆錄6(Javascript元素的常用屬性)

代碼包含如下:

1 創建懸停按鈕

 <img src="../image/1.jpg" onmouseover="document.images[0].src='../image/2.jpg'" onmouseout="document.images[0].src='../image/1.jpg'" />

2 設置焦點

<input type="text" name="txt1" value="hello" onfocus="document.form1.txt1.value='獲得該文本焦點'" onblur="document.form1.txt1.value='失去該文本焦點'" />

3 click事件:單擊or 雙擊

<input type="button" name="button2" value="雙擊or單擊" onclick="document.form1.button2.value='單擊'" ondblclick="document.form1.button2.value='雙擊'" />

4 下拉框<select></select>

5 創建網頁加載和卸載信息

onload onunload

具體代碼如下

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="js4.aspx.cs" Inherits="Javascript_js4" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script>
        function ee(event)
        {
            if(event.keyCode==38)
            document.write("You Press UP");
        }
    </script>
</head>
<body οnlοad="document.form1.txtLoad.value='頁面加載完畢'" οnunlοad="alert('goodbye')">
    <form id="form1" runat="server">
    <div>
     <input type="button" name="button1" value="檢查鼠標單擊" οnclick="document.form1.button1.value='change'" />
     <input type="button" name="button2" value="雙擊or單擊" οnclick="document.form1.button2.value='單擊'" οndblclick="document.form1.button2.value='雙擊'" />
     <%--創建懸停按鈕--%>
     <br />
     <img src="../image/1.jpg" οnmοuseοver="document.images[0].src='../image/2.jpg'" οnmοuseοut="document.images[0].src='../image/1.jpg'" />

    <%--設置焦點--%>   
    <input type="text" name="txt1" value="hello" οnfοcus="document.form1.txt1.value='獲得該文本焦點'" οnblur="document.form1.txt1.value='失去該文本焦點'" />
    <%--下拉框--%>
    <select name="s1" size="4" οnchange="document.form1.txt2.value=document.form1.s1.value">
    <option value="北京" selected="selected">北京</option>
    <option value="上海">上海</option>
    <option value="臺灣">臺灣</option>
    <option value="廣州">廣州</option>
    <option value="成都">成都</option>
    </select>
    <input type="text" name="txt2" value="City" />
    <input name="txtLoad" type="text" value="waiting...." />
    </div>
    </form>
</body>
</html>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章