<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
</head>
 
<body>
<form id="form1" name="form1" method="post" action="">
 <input type="text" name="test1" id="test1"/>
<input name="test2" type="text" id="test2" value="100" />
</form>
  <script>
    function f(){
  if(parseInt(document.getElementById('test1').value)<parseInt(document.getElementById('test2').value))alert('----');
    }              document.getElementById('test1').onblur=f;  
document.getElementById('test1').onkeyup=function(e){
      e=e||window.event;
      if(e.keyCode==13)f();
    }
    </script>
</body>
</html>

解决方案 »

  1.   


    在test1中输入 “1”回车,弹2次错误信息,请帮忙再优化一下。
      

  2.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>test</title>
    </head>  
    <body>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <form id="form1" name="form1" method="post" action="">
     
    <table width="300" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
    </table>
    </form>
      <script>
        function f(){
      if(parseInt(this.value)<parseInt($(this).parents('tr').find('input[name=test2]').val()))alert('错误!');
        }            
     $('input[name=test1]').blur(f).keyup(function(a){if(a.keyCode==13)f.call(this)})
        </script>
    </body>
    </html>
      

  3.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>test</title>
    </head>  
    <body>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <form id="form1" name="form1" method="post" action="">
     
    <table width="300" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
      <tr>
        <td> <input type="text" name="test1" id="test1"/></td>
        <td><input name="test2" type="text" id="test2" value="100" /></td>
        </tr>
    </table>
    </form>
      <script>
        function f(){
      if(parseInt(this.value)<parseInt($(this).parents('tr').find('input[name=test2]').val()))alert('错误!');
        }            
     $('input[name=test1]').blur(f).keyup(function(a){if(a.keyCode==13)f.call(this)})
        </script>
    </body>
    </html>
      

  4.   


    slwsss,在这段代码在使用过程中有个问题,报错是报错了,用户不理它,后面的操作一样进行。请帮忙完善一下,加个限制,报错后,焦点回到出错的input,只有等满足条件了才能做其它动作。
      

  5.   

      <script>
        function f(){
      if(parseInt(this.value)<parseInt($(this).parents('tr').find('input[name=test2]').val())){alert('错误!');this.focus();}
        }            
     $('input[name=test1]').blur(f).keyup(function(a){if(a.keyCode==13)f.call(this)})
        </script>