javaScript--05 DOM基础 12.7

来源:互联网 发布:可以证件照软件 编辑:程序博客网 时间:2024/05/21 09:39

formmethodactiononsubmitonresetonchangeselect、form.name.

<!DOCTYPE html>

<html lang="zh" id="htmlId">

    <head id="headId">

        <title>BOM基础</title>

        <meta charset="utf-8">

        <meta name="keywords" content=",,">

        <meta name="description" content="">

        <style>

            form p{

                display:inline;

            }

        </style>

    </head>


    <script type="text/javascript">

        function check(form){

            var span = document.getElementById("sname");

            var txt = form.username.value;

            if(txt == "")

            {

                span.innerText="填写姓名"

                form.username.focus();

                return false;//提交事件的特殊之处。

            }

            return true;

        }

        

        function resetFun(form){

            return false;

        }


        function selectChange(value,selectedIndex)

        {

            alert(value+selectedIndex);//弹出中国0”英国1”美国2”“deguo3”

        }


        function formsClick(){

            var theform = document.forms[1];

            theform.username.value="theButton";

            alert(theform);

        }


        function funChange(obj){

            //text input的内容发生改变,且失去焦点

            alert(obj.value);

        }

        

        function documentAll(){

            var arryy = document.all[0];

            alert(arryy);

        }

        

    </script>


    <body id="bodyId">

        

        <form method="post" action="%E5%B7%A5%E8%B5%84%E6%9D%A1.html" onsubmit="return check(this)" onreset="return resetFun(this)">

            姓名:<input type="text" name="username"><span id="sname"></span>

            <input type="submit" value="提交">

            <input type="reset" value="重置">

            <input type="text" name="textInput" value="容发生改变,且失去焦点时调用" onchange="funChange(this)">

        </form>

        

        <form>

            <select onchange="selectChange(this.value,this.selectedIndex)">

                <option>中国</option>

                <option>英国</option>

                <option>美国</option>

                <option value="Germany">德国</option>

            </select>

            <input type="button" value="document" onclick="documentAll()">

            <input type="button" name="username" value="name=username" onclick="formsClick()">

            <input type="button" value="name!=username" onclick="formsClick()">

        </form>

        

    </body>    

</html>


0 0