显示或隐藏表单元素 [英] Show or hide form element
问题描述
我有一个html表单 - 在一个文本字段上,如
I have one html form - On that one text field like
<input type = "text" name = "age" value = "" id = "txt_age">
在年龄值上,我必须显示这个元素,如 -
On the value of age i have to show this element like -
<select name = "married">
<option value = "Yes">Yes</option>
<option value ="No">No</option>
</select>
如果年龄> 18岁,那么已婚领域将被显示形式,否则将其隐藏。此年龄> 18岁条件存储在数据库中。随着年龄的变化,结婚字段切换(显示/隐藏)。
如何使用javascript / jquery进行操作。请建议。
If age>18 then married field will be shown to form otherwise hide it.This age>18 condition is stored in database.As value of age changes married field toggle(show/hide). How can i do it with javascript/jquery.Please suggest.
有关更多信息,所有这些字段都是动态生成的。所以我想添加onchange =somefuction(condition);当条件满足时,在创建然后查找字段时显示年龄,也在DB中。
For more information, all these fields are genereated dynamically.So i was thinking to add onchange = "somefuction(condition);" with age while creating then look for field are to be shown when condition is satisfied, is also in DB.
或
我认为有一种解决方案 -
本案例中的字段结婚将寻找年龄变化的价值。然后结婚将隐藏/显示自己。但问题是,如何结婚观察年龄领域或调用javascript函数。
很抱歉没有解释完整的问题。
One solution may i think that -
The field in this case married will look for value of age changes.Then accordingly married will hide/show itself.But problem is that how married observe age field or call javascript function.
Sorry for not explaining full problem.
推荐答案
在选择中添加id =已结婚并使用类似的内容。
add id="married" to the select and use something like this.
$("#txt_age").blur(function() {
if(parseInt($(this).val() > 18) {
$("#married").show();
} else {
$("#married").hide();
}
});
这篇关于显示或隐藏表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!