php - jquery - 更改输入时的raido按钮选择
问题描述
我有这个代码:
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 中:检查接收否则检查发送。
你能帮忙吗
解决方案
使用此代码。
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
推荐阅读
- php - 如何修复“重定向你太多次”。
- c - 默认安装的 Code::Blocks 在程序结束时不会因“按任意键继续”而暂停
- c - “UA_ReadRequest_deleteMembers”错误问题的 OPC-UA 函数
- python - 从python检测macos中的暗模式
- xamarin - Cocossharp 精灵掩蔽
- python - 如何在嵌套字典中查找重复项或重复项?
- php - 在 RESTful API 中重写 URL
- java - Runtime.exec 不会运行 javac,但命令行会
- r - 在 r 中创建一个稀疏矩阵,每行具有一组整数值
- javascript - 未运行 Jest+Enzyme API 模拟调用测试