表单事件

来源:互联网 发布:啥软件下种子 编辑:程序博客网 时间:2024/04/26 17:48

<!DOCTYPE html>

<html>

<head>

<metacharset="UTF-8">

<title></title>

<styletype="text/css">

input{

width:200px;

height:200px;

color: plum;

font-size:100px;

background-color: palegreen;

}

</style>

</head>

<body>

<formid="form1" action="http://www.baidu.com">

<inputtype="submit" value="提交" />

</form>

<scripttype="text/javascript">

/* 在表单中,通过点击submit按钮,可以将表单中的内容提交到指定的URL中,我们也可以指定submit触发的事件,进行自定义操作。如本例中,点击submit按钮,弹出提示框 */

varform1 = document.getElementById("form1");

form1.onsubmit= function(){

alert("onsubmit触发事件");

// 阻止默认事件 方法一(比较好,优先):

event.preventDefault(); 

// 阻止默认事件 方法二:

// return false;

}

</script>

</body>

</html>

0 0
原创粉丝点击