【问题标题】:i have two text box first text box value 1 means second text box value can't exceed 5我有两个文本框第一个文本框值1表示第二个文本框值不能超过5
【发布时间】:2015-08-10 21:36:25
【问题描述】:

我有两个文本框第一个文本框值 1 表示第二个文本框值不能超过 5 那样...第一个文本框值2 表示第二个文本框值可以超过 10。不是字符数

请指教

【问题讨论】:

  • 什么???你试过的代码在哪里?
  • 你能展示你迄今为止尝试过的代码吗??
  • 不,我没有写任何代码。但我正在搜索代码,但给出的例子只有字符数

标签: javascript html jquery-ui


【解决方案1】:

 function result(){
      if( $("#f2").val() > $("#f1").val()*5 ) $("#f2").val($("#f1").val()*5);
    }

    $("#f1").keyup(result).change(result);
    $("#f2").keyup(result).change(result);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <input type="number" id="f1" value=1/>
    <input type="number" id="f2" value=2/>

【讨论】:

    【解决方案2】:

    只有 javascript !

     function result(){
          if( f2.value > f1.value*5 )
              f2.value = f1.value*5;
        }
    
        
    <form>    
        <input type="number" id=f1 onchange="result()" onkeyup="result()"/>
        <input type="number" id=f2 onchange="result()" onkeyup="result()"/>
    </form>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-11
      • 2014-12-13
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多