请您写出一段html/js代码, 实现下面的页面功能:一个商品查询界面, 包含一个产品编码输入框. 用户可以点击提交按钮或者直接回车实现提交; 提交时, 如果输入框没有输入, 则用消息窗口提示用户”请先输入”并停止提交.

解决方案 »

  1.   

    <input type="text" onsubmit="test(this)"/>
    <script>
    function test(o){
       if(o.value==""){alert("请先输入");return false;}
       else return true;
    }
    </script>
      

  2.   


    <input type="text" id="aaa" onsubmit="test"/>
    <input type="submit"
    <script>
    function test(){
        var a = document.getElementById("test").value;
       if(a ==""){alert("请先输入");return false;}
       else return true;
    }
    </script>
      

  3.   

    好像你们都忽略了个回车提交...至少触发事件的时候也看看keyCode等于13不撒!!
      

  4.   

    <form  onsubmit="test">
    <input type="text" id="aaa"/>
    <input type="submit" />
    </form>
    <script>
    function test(){
        var a = document.getElementById("test").value;
       if(a ==""){alert("请先输入");return false;}
       else return true;
    }
    </script>
      

  5.   

    <table border="0">
      <tr>
        <td>产品编码:</td>
        <td><input type="text" id="code" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input type="submit" value="查询" onclick="search()" />
        </td>
      </tr>
    </table>
    <script type="text/javascript">
    function search(){
    if(document.getElementById("code").value=="")
    {
    alert("请先输入!");
    document.getElementById("code").focus;
    return false;
    }
    }
    </script>
    按钮类型为submit默认回车提交的
      

  6.   

    这年代赚分真不容易
    <form onsubmit="test">
    <input type="text" id="aaa"/>
    <input type="submit" />
    </form>
    <script>
    function test(){
      var a = document.getElementById("test").value;
      if(a ==""){alert("请先输入");return false;}
      else return true;
    }
    </script>