为什么提交之后是这样的?

http://img.mukewang.com/59783e6e0001da1612010667.jpg

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
   <title>get</title>
</head>
<body>
<form action=""id="forml">
   <p>评论:</p>
   <p>姓名:<input type="text" name="username"id="username"></p>
   <p>内容:<textarea name="content"  cols="30" rows="10"></textarea></p>
   <p><input type="button" id="send" value="提交"></p>
</form>
<div class="comment">已有评论:</div>
<div id="resText"></div>
<script src="static/js/jquery-1.8.3.min.js"></script>
<script>
   $(function () {
       $("#send").click(function () {
           $.post("get.jsp",{
               username:$("#username").val(),
               content:$("#content").val()
           },function (data,textStatus) {
               $("#resText").append(data);
           })
       })
   })
</script>
</body>
</html>

薏苡x
浏览 1564回答 1
1回答

李晓健

form里应该有一个提交按钮,也就是type=submit的button; 如果你没有指定这个type,他就会默认把第一个button当成提交按钮,当你点击里他提交form,而你的form的action是空,提交时就相当于提交到当前页面,也就是刷新页面。解决方法两种,一个是在你的点击事件里阻止form的默认提交,第二个就是最后那个按钮不要用button,可以用a,a的href="javascript:;"
打开App,查看更多内容
随时随地看视频慕课网APP