本文介绍了根据用户输入使用Jquery显示/隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<li class="numeric optional" id="contest_max_retweet_input"><label for="contest_max_retweet">Winning retweet number</label><input id="contest_max_retweet" name="contest[max_retweet]" size="50" type="text" /></li>
<li class="numeric optional" id="contest_numofwinners_input"><label for="contest_numofwinners">Number of winners (1-100)</label><input id="contest_numofwinners" name="contest[numofwinners]" size="50" type="text" /></li>
如果用户在以下字段中指定了一个值:Competition_max_retweet_input,如何使用JQuery隐藏该字段:Competition_numofwinners_input?
How can I use JQuery to Hide the field: contest_numofwinners_input if there is a value specified by the user in the field: contest_max_retweet_input?
推荐答案
您可以尝试以下方法:
$('#contest_max_retweet').change(
function(){
if ($(this).val().length) {
$('#contest_numofwinners').hide();
}
else {
$('#contest_numofwinners').show();
}
});
这仅隐藏input
元素本身, 不 包含其中的li
或相应的label
元素.
This hides only the input
element itself, not the containing li
, or corresponding label
, element.
这篇关于根据用户输入使用Jquery显示/隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!