首页 > html a标签提交表单失败

html a标签提交表单失败

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<base href="<%=basePath%>">

<title>My JSP 'buy1.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function handlesubmit(){
    document.ball.submit();
}
</script>

</head>

<body>

<h1>各种球大甩卖,一律八块:</h1>
<form method="post" action="display.jsp" name="ball">
<input type="checkbox" name="good" value="篮球">篮球
<br>
<input type="checkbox" name="good" value="足球">足球
<br>
<input type="checkbox" name="good" value="排球">排球
<br>
<input type="submit" name="submit">
<input type="reset" name="reset">
</form>
<a href="buy2.jsp" onclick = "handlesubmit();">买点别的</a>
<a href="display.jsp" onclick = "handlesubmit();">查看购物车</a>

</body>
</html>
点击查看购物车和买点别的两个链接的时候只执行了跳转,onclick事件没有被执行,这是为什么?


onclick肯定执行了,不然你在里面写个alert试试


你这么写有问题,在执行函数之前就已经跳转了。你应该先执行onclick函数,然后在函数执行完以后执行连接的跳转。


因为跳转了啊,跳转时已不是这个页面,自然无法执行,执行了你也看不到。

【热门文章】
【热门文章】