表单提交方式:
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>