表单提交的方式

表单提交方式:
1. Submit提交

<form>
……
    <input type=”submit”  />
</form>  

2.使用button提交表单

<form>
<input  type=”button” onclick=”form1();”/>
</form>
function form1(){
}

3.使用超链接提交

<a href=”hello.html?username=1234(即添加提交的参数)”> 使用超链接提交</a>
  • 常用的事件响应方法:

onclick()鼠标点击事件
onchange()改变内容(一般和select一起使用)
onfocus()得到焦点
onblur()失去焦点

  • 完整代码如下:
 <html>
 <head>
  <title>HTML示例</title>
  <style type="text/css">

  </style>
 </head>
 <body>
 <form id="form1" action="hello.html">
    <input type="text" name="username"/>
    <!--onfocus()&onblur();用法-->
    <input type="text" id="name1" name="name1" value="please input" onfocus="focus1();" onblur="blur1();"/>
    <br/>
    <!--提交方式1-->
    <input type="submit"/>
    <br/>
    <!--提交方式2-->
    <input type="button" value="提交" onclick="form1();">
 <form>
    <br/>
    <!--提交方式3-->
 <a href="hello.html"?username="1234">使用超链接提交</a>
 <script type="text/javascript">
    function form1(){
      var form_1=document.getElementById("form1");
      form_1.action="hello.html";//设置提交到另一个html网页
      form_1.submit();
     }
     //实现鼠标点击得到焦点时,输入框内容清空
     function focus1(){
       var input1=document.getElementById("name1");
       input1.value="";
     }
     //实现鼠标点击别处失去焦点时,输入框默认内容还原
     function blur1()
     {
      var input1=document.getElementById("name1");
       input1.value="please input";
     }
 </script>
 </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值