=======================================
这么说吧:
function massage()是一个函数,message是函数的名,打个比方,好比是你在网页里偷偷放了了一个礼花弹(function),这个礼花弹的名字叫做massage。礼花弹一旦升空后的效果是什么呢?就是将跳出一个警告框,上面写着“该提示框是通过 onload 事件调用的”。
onload应该是礼花的引爆装置,网页加载到onload这行代码的时候,礼花就自动升空开放了。这也就是“onload 事件调用”。
你这是一个表单的提交,如果想做无刷新页面提交,需要学习新技术:AJAX。我给你演示一个利用Jquery的Json格式无刷新数据提交:
<script type="text/javascript" src="JS/jquery.js"></script>//导入JQUERY的JS包
<script type="text/javascript">
function addbk(){
var bname = document.getElementById("bname").value//根据ID获得值
var bauthor = document.getElementById("bauthor").value
var bclass = document.getElementById("bclass").value
var bnumber = document.getElementById("bnumber").value
$.post("remote/remote_add_content.php",{"book.bname":bname,"book.bauthor":bauthor,"book.bclass":bclass,"book.bnumber":bnumber},function(date){
alert(date["massage"])//提交成功后,弹出返回的massage信息
document.getElementById("submit").reset()//弹出框后,清空表单
})
}
</script>
表单中,只需要定义一个button,调用addbk()方法就可以了。
<input type="button" id="submit" value="提交" onclick="addbk()">
先定义一个用户类,test包下package test
import java.io.Serializable
public class User implements Serializable{
private static final long serialVersionUID = 4857377833428882294L
private String name
private String password
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public String getPassword() {
return password
}
public void setPassword(String password) {
this.password = password
}
}
之后是jsp页面
<html>
<%@ page language="java" import="test.User" pageEncoding="gbk"%>
<%
String path = request.getContextPath()
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"
%>
<head>
<%String name=request.getParameter("name")
String password = request.getParameter("password")
if(name!=null &&password != null){
User user = new User()
user.setName(name)
user.setPassword(password)
session.setAttribute("user", user)
}%>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />
<title></title>
<style type="text/css">
a{ color:#000font-size:12pxtext-decoration:none}
a:hover{ color:#900text-decoration:underline}
body{background:filter:progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#ffffff,endColorStr=#003366)overflow:hidden}
#massage_box{ position:absoluteleft:expression((body.clientWidth-350)/2)top:expression((body.clientHeight-200)/2)width:350pxheight:200pxfilter:dropshadow(color=#666666,offx=3,offy=3,positive=2)z-index:2visibility:hidden}
#mask{ position:absolutetop:0left:0width:expression(body.clientWidth)height:expression(body.clientHeight)background:#666filter:ALPHA(opacity=60)z-index:1visibility:hidden}
.massage{border:#036 solidborder-width:1 1 3 1width:95%height:95%background:#fffcolor:#036font-size:12pxline-height:150%}
.header{background:#036height:10%font-family:Verdana, Arial, Helvetica, sans-seriffont-size:12pxpadding:3 5 0 5color:#fff}
</style>
</head><body>
<div id="massage_box"><div class="massage">
<div class="header"><div style="display:inlinewidth:150pxposition:absolute">
登陆
</div>
<span onClick="massage_box.style.visibility='hidden'mask.style.visibility='hidden'" style="float:rightdisplay:inlinecursor:hand">×</span></div>
<ul style="margin-right:25">
<form action="test.jsp">
<table>
<tr>
<td>用户名</td>、
<td><input name="name" /></td>
</tr>
<tr>
<td>密码</td>
<td><input name="password" type="password"/></td>
</tr>
</table>
<input type="submit" value="button"/>
</form>
</ul></div></div>
<div id="mask"></div>
<%if(session.getAttribute("user")!=null){ %>
<%User user = (User)session.getAttribute("user")%>
欢迎 <%=user.getName() %>
<%} else{%>
<span onClick="mask.style.visibility='visible'massage_box.style.visibility='visible'" style="cursor:hand">
<a href="#">登陆</a>
</span>
<%} %>
</body>
</html>
需要用到TOMCAT服务器
你自己试一试看是不是和百度一样的弹窗口的