用button怎么实现表单的验证和页面的跳转

如题所述

button和submit的区别及使用js实现页面跳转的方式
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
type=button //就单纯是按钮功能
type=submit //是发送表单

但是对于从事WEB UI的人应该要注意到,使用submit来提高页面易用性:
使用submit后,页面支持键盘enter键操作,而很多WEB软件设计师,可能没有注意到submit统
一。

用button后往往页面不支持enter键了。所以需要支持enter键,必须要设置个submit,默认enter键对页面第一个submit进行操作。

[java] view plain copy print?在CODE上查看代码片派生到我的代码片
<input type="submit" name="b1" value="提交" onClick="bt_submit_onclick()">

执行完onClick,转到action。可以自动提交不需要onClick。所以说onclick这里可以不要。

[java] view plain copy print?在CODE上查看代码片派生到我的代码片
<input type="button" name="b1" value="提交" onClick="bt_submit_onclick()">

执行完onClick,跳转文件在js文件里控制。提交需要onClick。

比如:
1、
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
onclick="form1.action='a.jsp';form1.submit();"

这样就实现了submit的功能了。

2、
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
<form name="form1" method="post" action="http://www.sina.com.cn">
<input type="button" name="Button" value="Button" onClick="submit()">
</form>

3、
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
<input type="button" name="Button" value="Button" onClick="javascript:windows.location.href="你的url"">

js实现页面跳转的几种方式:

第一种:
[js] view plain copy print?在CODE上查看代码片派生到我的代码片
<script language="javascript" type="text/javascript">
function test(){
window.location.href="login.jsp?backurl="+window.location.href;
}
</script>

第二种:
[js] view plain copy print?在CODE上查看代码片派生到我的代码片
<script language="javascript">
function test(){
alert("返回");
window.history.back(-1);
}
</script>

第三种:
[js] view plain copy print?在CODE上查看代码片派生到我的代码片
<script language="javascript">
window.navigate("top.jsp");
</script>

第四种:
[js] view plain copy print?在CODE上查看代码片派生到我的代码片
<script language="JavaScript">
function test(){
self.location='top.htm';
}
</script>

第五种:
[js] view plain copy print?在CODE上查看代码片派生到我的代码片
<script language="javascript">
function test(){
alert("非法访问!");
top.location='xx.jsp';
}
</script>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-05-14
1、这应该是在jsp页面实现的按钮交互事件

2、一般会通过form表单来提交事件
3、form表单中给出的一个action为对应的路径
4、如果是三大框架则到struts.xml里面配置到对应的Action类中处理逻辑
5、如果是Servlet的话则在web.xml里面配置到对应的Servlet类中处理逻辑
6、最后通过return或者response等形式将值转发或重定向等即完成了一个验证交互本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网