<script>
 function set(operation) {
 alert(operation);
 if(operation=='zhuye')
 {
        with (document.forms[0]) {
            method.value = operation;
        }    
  }
  else
  {
  with (document.forms[0]) {
            method.value = operation;
        }  
        if(document.getElementsByName("name")[0].value!="")
        {
        doReadOnly();    
        }
  }     
}
 function doReadOnly() 
 {
 
  document.getElementsByName("city")[0].disabled="true" ;
  document.getElementsByName("state")[0].disabled="true" ;
  document.getElementsByName("address")[0].disabled="true" ;
  document.getElementsByName("phone")[0].disabled="true" ;
  document.getElementsByName("sex")[0].disabled="true" ;
  document.getElementsByName("age")[0].disabled="true" ;
 }  
    
    
 function Empty()
 {
  document.getElementsByName("name")[0].value="" ;
  document.getElementsByName("city")[0].value="" ;
  document.getElementsByName("state")[0].value="" ;
  document.getElementsByName("address")[0].value="" ;
  document.getElementsByName("phone")[0].value="" ;
  document.getElementsByName("sex")[0].value="" ;
  document.getElementsByName("age")[0].value="" ; 
 }   
 function doSumit(){
if(event.keyCode == 13){
set('chaxun');
}
}
 </script>
<body onkeydown="doSumit()">
<html:form action="AjaxobjAction.do">
<input type="hidden" name="method"/> 
<td><html:submit onclick="set('zhuye')" property="button1">主页</html:submit></td>
<table bgColor="#ffffff" cellpadding="1" cellspacing="1" align="center"> 
······
<td><html:submit onclick="set('chaxun');">查询</html:submit></td>
为什么我按回车键  operation先等于‘chaxun’然后又等于‘zhuye’  doSumit()里面明明是set(‘chaxun’)  为什么又等于‘zhuye’了???    

解决方案 »

  1.   

    你的function set(operation)函数写得有问题
      

  2.   

    先等于‘chaxun’然后又等于‘zhuye’??什么意思 你在
    alert(operation);
    后面再加一句
    alert(operation=='zhuye');  结果是false
    怎么然后又等于‘zhuye’  ?
      

  3.   

    doSumit()  里面我是set(‘chaxun’)所以function set(operation)  里面OPERATION 就应该是等于‘chaxun’的  
    但是我alert(operation);  会先提示 chaxun   然后又提示zhuye     所以就等于是执行  set(‘chaxun’)  以后   不知道那里有接着执行了一遍set(‘zhuye’) 
      

  4.   

    我 set(‘chaxun’)    那么    if(operation=='zhuye')
    这里应该是等于false  执行else里面的语句       
        但是后面不知道那里又set(‘zhuye’)    使得if(operation=='zhuye') 等于true 
     
      

  5.   

    代码的贴的不完整 至少把form标签贴出来
    不然没法再现你说的那种效果 js会出错
      

  6.   

    1,还有一个问题 你说的情况是 一次回车 执行了两次set方法?
    2,那你把那个查询摁钮里的onclick="set('chaxun'); 先去掉 在试验一次!
      

  7.   

    查询按钮去掉  onclick   回车   直接白屏了    就是说set('chaxun')和set(‘zhuye’)都没执行    我Action里面查询按钮  查询数据库成功之后为了显示数据我return mapping.findForward("chaxun");了一次  重载查询页面一次   会不会是这个原因 ?   要不就是 function set(operation)  的问题了