日期:2014-05-17 浏览次数:20621 次
if(in_flag==1){
document.getElementByName("name").onfocus;
}else if(in_flag==2){
document.getElementByName("age").onfocus;
}
Java code?12345 if(in_flag==1){ document.getElementByName("name").onfocus; }else if(in_flag==2){ document.getElementByName("age").onfocus;}
如果你是在jsp初始化的时候,就要着效果,就加在body标签的onload(……
<script type="text/javascript">
var xhr;
function add()
{
xhr = new ActiveXObject("Microsoft.XMLHTTP"); //定义xhr对象
xhr.open("post","myajax.do",true); //要加.do,不要加/
//3. 设置请求头
xhr.setRequestHeader("cache-control","no-cache"); //不缓存
xhr.setRequestHeader("content-type","application/x-www-form-urlencoded"); //enctype=multipart/form-data
//4. 发送数据
//xhr.send("uid="+f1.uid.value+"&age=18&gender=1"); //空的
xhr.send("addlei="+jiuhuiForm.addlei.value+"&jiupk="+jiuhuiForm.jiu_pk.value);
//5. 开始等待,onreadystatechange轮询服务器是否处理完成
xhr.onreadystatechange = function() {
//readystate=4表示servlet处理完成,status=200表示成功处理
if(xhr.readystate==4 && xhr.status==200) {
//6. 局部刷新,用js技术
var str = xhr.responseText; //接收的响应是普通文本
document.all.msg.innerText = str;
}
}
}
response.setContentType("text/html;charset=utf-8"); //只能是utf-8
response.setHeader("cache-control", "no-cache"); //不缓存
response.setDateHeader("expires", 0); //让数据响应后马上过期,不缓存
//4.发送响应数据
PrintWriter out;
try {
out = response.getWriter();
out.println(in_flags);
out.flush();