【问题标题】:jquery - change raido button selection on inputjquery - 更改输入时的单选按钮选择
【发布时间】:2020-04-01 17:02:06
【问题描述】:

我有这个代码:

Amount<input type='text' name='amount' size='10'  >
  <br>      
Free<input type='text' name='fees' size='10' > 
 <br> 
 ------------
 <br>
<input type='radio' name='amount_type' value='Receive'checked> Receive<br>
<input type='radio' name='amount_type' value='Send'> Send<br>
-------------
 <br>
        
<input type='radio' name='curr' value='LBP'checked> LBP<br>
<input type='radio' name='curr' value='USD'> USD<br>

我想做的是

  • 如果金额超过 5000,检查单选按钮 curr : value LBP else check usd

  • 如果插入费用,在单选按钮 amount_type 中:检查接收否则检查发送。

你能帮忙吗

【问题讨论】:

  • 这能回答你的问题吗? jQuery set radio button
  • 不,我需要条件参数,如果 true 将设置重做按钮
  • 看看我的回答。 @侯赛因
  • 我只是想知道为什么我提出的重复标志被拒绝了。问题通常是关于如何更改单选按钮的值。它是否仅仅因为建议的答案缺少if 声明而被拒绝?大声笑

标签: php jquery html


【解决方案1】:

使用此代码。

Amount<input type='text' name='amount' size='10' id='amount'  >
  <br>      
Free<input type='text' name='fees' size='10' id='fees' > 
 <br> 
 ------------
 <br>
<input type='radio' id='receive' name='amount_type' value='Receive'checked> Receive<br>
<input type='radio' id='send' name='amount_type' value='Send'> Send<br>
-------------
 <br>

<input type='radio' id='lbp' name='curr' value='LBP'checked> LBP<br>
<input type='radio' id='usd' name='curr' value='USD'> USD<br>

jquery

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    $("#usd").prop("checked", true);
    $("#send").prop("checked", true);
    $("#amount").on("input", function(){
        // Print entered value in a div box
        if($("#amount").val() > 5000){
            $("#lbp").prop("checked", true);
        }else{
            $("#usd").prop("checked", true);
        }
    });
    $("#fees").on("input", function(){
        // Print entered value in a div box
        if($("#fees").val() > 0){
            $("#receive").prop("checked", true);
        }else{
            $("#send").prop("checked", true);
        }
    });
});
</script> 

查看在线演示:DEMO

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-12
  • 2018-09-11
  • 2014-07-02
相关资源
最近更新 更多