javaScript--05 DOM基础 12.7

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" οnsubmit="return check(this)" οnreset="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="容发生改变,且失去焦点时调用" οnchange="funChange(this)">

        </form>

        

        <form>

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

                <option>中国</option>

                <option>英国</option>

                <option>美国</option>

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

            </select>

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

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

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

        </form>

        

    </body>    

</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值