1. 程式人生 > >js表單提交方式與表單事件

js表單提交方式與表單事件

1、表單提交方式

(1)使用submit提交

<form>
        ...
        <input type="submit">
    </form>

提交form內內容

(2)使用button提交表單

body內程式碼

<form id="form1">
        <input type="text" name="username">
        <br>
        <input type="button" value="提交" onclick="form1()">
</form>

js程式碼

<script type="text/javascript">
        function form1() {
            var form1 = document.getElementById("form1");
            form1.action = "user.html";
            form1.submit();
        }
    </script>

(3)使用超連結提交

<a href="hello.html?username=123456">使用超連結提交</a>

2、表單事件
onclick :滑鼠點選事件
onchange :改變內容(一般和select使用)
onfocus :得到焦點
onblur :失去焦點