[英]javascript show text input field
I am using the following coding in a website I am building but rather than the text input field showing if one option is selected, I need it show if the user selects other options as well? 我在正在建立的网站中使用以下代码,但不是在文本输入字段中显示是否选择了一个选项,而是在用户是否还选择其他选项时需要显示它吗?
for example oit currently shows the text input field if the user selects option 2 from the select menu but need to show as well if the user selects option 4 in the select menu, below is my jfiddle code so far 例如,如果用户从选择菜单中选择选项2,但oit当前显示文本输入字段,但是如果用户在选择菜单中选择选项4,也需要显示文本输入字段,到目前为止,这是我的jfiddle代码
it currently shows the extra text input fields when Domestic+ is selected in the select menu but need the text input fields to show as well when Commercial is selected within the dropdown menu 当前在选择菜单中选择Domestic +时,它会显示额外的文本输入字段,但在下拉菜单中选择Commercial时,它也需要显示文本输入字段
I found something similar on stackoverflow, see link below 我在stackoverflow上找到了类似的东西,请参见下面的链接
<http://stackoverflow.com/questions/21007591/using-jquery-to-hide-form-elements-based-on-selected-dropdown-option/33055467#33055467>
<http://jsfiddle.net/gxxkdz2m/2/>
Thank you in advance 先感谢您
Ian 伊恩
Is this what you mean? 你是这个意思吗? I added comments explaining the code where I changed it.
我添加了注释,解释了更改代码的地方。
$(document).ready(function () {
$('#support select[name="support_plans"]').change(function () {
// get selected plan value
var plan = $('#support select[name="support_plans"] option:selected').val();
// check whether 'Domestic+' or 'Commercial+' is selected
if (plan == 'Domestic+' || plan =='Commercial+') {
$('#extra').show();
} else {
$('#extra').hide();
}
});
});
Fiddle of my Version (updated your fiddle). 我版本的小提琴(更新了您的小提琴)。
http://jsfiddle.net/gxxkdz2m/4/ http://jsfiddle.net/gxxkdz2m/4/
use this javascript code: 使用此javascript代码:
$(document).ready(function () {
$('#support select[name="support_plans"]').change(function () {
if ($('#support select[name="support_plans"] option:selected').val() == 'Domestic+') {
$('#extra').css('display', 'inline');
} else {
$('#extra').css('display', 'none');
}
});
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.