<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<body bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0" ms_positioning="GridLayout"
    onunload="return pageunload()">
    <form name="Form1">
    <table>
        <tr>
            <td>
                <input name='ProNum_1' class='justify' type='text' style='ime-mode: disabled; width: 60px;'
                   onblur ='javascript:GetSum(1)' onkeypress='return floatkey()'>
            </td>
            <td>
                <input name='price_1' class='justify' type='text' style='ime-mode: disabled; width: 60px;'
                    onkeypress='return floatkey()'>
            </td>
        </tr>
         <tr>
            <td>
                <input name='ProNum_2' class='justify' type='text' style='ime-mode: disabled; width: 60px;'
                    onblur='javascript:GetSum(2)' onkeypress='return floatkey()'>
            </td>
            <td>
                <input name='price_2' class='justify' type='text' style='ime-mode: disabled; width: 60px;'
                    onkeypress='return floatkey()'>
            </td>
        </tr>
    </table>
    </form>
</body>
< ml><script language="javascript">
 function GetSum(rowid) 
 { 
   var ProNum=eval("document.Form1.ProNum_"+rowid).value; 
    if (ProNum=="")
    {
      alert("请输入数量!");
      eval("document.Form1.ProNum_"+rowid).focus(); 
      return false;
    }
}
</script>目的是强制用户数量一栏必须输入。
第一行获得光标时,如果用户不输入直接点下一行数量那一栏就会一直弹出请输入数量产生死循环。
望指点focus()  onblur结合使用产生死循环如何解决。

解决方案 »

  1.   

    强制用户行为是不人性化的,应该是在必要的时候给出善意的提醒!
    建议放弃这种方法,改为在提交时进行验证!
    如果真有非强制输入不可的理由,不要用alert弹出提示,采用在输入框边上显示DIV进行提示就不会有这种现象了。
      

  2.   


    <script language="javascript"> 
    var currentID=null;
    function GetSum(rowid) 

      var ProNum=eval("document.Form1.ProNum_"+rowid).value; 
        if (ProNum=="") 
        { 
      if(currentID==null||currentID==rowid)
      {
    alert("请输入数量!"); 
    eval("document.Form1.ProNum_"+rowid).focus(); 
    currentID=rowid;
    return false; 
          }
      else
      {
        currentID=null;
      }
        } 
    }
    </script>