jQuery-根据输入字段更改隐藏值 [英] jQuery - Change hidden value based on input field
问题描述
我正在使用一个表单字段来捕获特定情况的统计信息.我需要基于两个文本字段的输入来更改隐藏字段的值.我将用简单的英语描述该功能.将其翻译成功能良好的jQuery脚本的帮助将不胜感激.
I am using a form field to capture stats of a particular situation. I need the value of a hidden field to change based on the input of two text fields. I will describe the function in plain English. Help translating this to a functioning jQuery script would be greatly appreciated.
隐藏字段等于'yes',其中field_1的值等于4&& field_2等于2 或者 隐藏字段等于是",其中字段_1的值等于3&& field_2等于1 或者 隐藏字段等于是",其中字段_1的值等于2 别的 隐藏字段等于否"
Hidden field equals 'yes' where the value of field_1 equals 4 && field_2 equals 2 or Hidden field equals 'yes' where the value of field_1 equals 3 && field_2 equals 1 or Hidden field equals 'yes' where the value of field_1 equals 2 else Hidden field equals 'no'
正如该语句的结构所示,我首先是一名PHP开发人员.我认为这可以通过jQuery完成.如果没有,请给我替代方法.谢谢!
As indicated by the structure of the statement, I'm a php developer first. It is my assumption that this can be done via jQuery. If not, provide me with an alternative. Thanks!
推荐答案
希望这会有所帮助.如果您的字段有所不同(例如,如果它们是复选框),请查看 jQuery api .
Hope this helps. Check out jQuery api incase your fields are different some how (like if they are checkboxes)
var field1 = parseInt($('#field_1').val());
var field2 = parseInt($('#field_2').val());
if((field1 == 4 && field2 == 2) || (field1 == 3 && field2 == 1) || field1 == 2){
$('#hidden').val('yes')
} else {
$('#hidden').val('no')
}
这篇关于jQuery-根据输入字段更改隐藏值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!