function check() 

  if(document.getElementById("txt_code").value=="") 
  {
    alert("单号不能为空,请填写!"); 
    return false; 
  } 
  else
  {
    document.getElementById("txt_code").value="123456"; 
  }

解决方案 »

  1.   

    如果是调用其他的function呢?
    如果单号不为空,则执行,否则不执行
      

  2.   

      if(document.getElementById("txt_code").value=="")
      {
        alert("单号不能为空,请填写!");
        return false;
      }
      else
      {
        //document.getElementById("txt_code").value="123456"; 换成你要调用的function
        test();
      } 
      

  3.   

    不好意思 ,是这样的:
    function check() 

    if(document.getElementById("txt_code").value=="") 
    {alert("单号不能为空,请填写!"); 
    return false; 

    if(document.getElementById("txt_nmae").value=="") 
    {alert("名称不能为空,请填写!"); 
    return false; 


    //////////////////////// 
    function pp() 

    check(); 
    document.getElementById("txt_code").value="123456"; 
    return false; 

    如果这样写,不管单号或名称是否为空,都会继续执行document.getElementById("txt_code").value="123456"; 
    如何怎么写才能当check()条件不满足时不执行document.getElementById("txt_code").value="123456";否则执行 
      

  4.   

    加个判断呗  把pp()改一下function pp() 

    if(check()!=false){ 
    document.getElementById("txt_code").value="123456"; 
    return false; 
    }

      

  5.   

    this?<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 1</title>
    </head><body>
    <input id="txt_code" onblur="pp(this)"> 
    <script language="javascript">
    <!--
    function check() { 
        if(document.getElementById("txt_code").value==""){
            return false; 
        }
        return true 
    } function pp(obj){ 
        if(!check()){
            alert("单号不能为空,请填写!")
            return obj.focus()
        }
        else{ newFun()}
    }function  newFun(){
        document.getElementById("txt_code").value="123456";
    }
    //-->
    </script>
    </body>
    </html>
      

  6.   

    问这样很有意思的.
    我在想,你写code 多长时间了.