jQuery:如果特定的< select>选项被选中了吗? [英] jQuery: Showing a div if a specific a <select> option is selected?
问题描述
我正在购物车的地址页面上.有2个<select>
框,一个用于国家",一个用于区域".
I'm working on the address page for a shopping cart. There are 2 <select>
boxes, one for Country, one for Region.
有6个标准国家/地区可用,否则用户必须选择其他国家/地区". <option>
元素都有一个数字值-其他国家/地区"为241.我需要做的是,如果用户选择其他国家/地区",则隐藏区域<select>
,并显示一个文本区域.
There are 6 standard countries available, or else the user has to select "Other Country". The <option>
elements all have a numeric value - Other Country is 241. What I need to do is hide the Region <select>
if the user selects Other Country, and also display a textarea.
非常感谢任何帮助!
推荐答案
您需要将一个函数绑定到选择列表,以便在更改列表时,您的函数可以决定是否显示div.像这样的东西(未经测试,希望在语法上接近). 这是一个实时示例 .
You need to bind a function to the select list so that when it changes, your function decides if the div should be shown. Something like this (untested, hopefully syntactically close). Here's a live example.
$(document).ready( function() {
$('#YourSelectList').bind('change', function (e) {
if( $('#YourSelectList').val() == 241) {
$('#OtherDiv').show();
}
else{
$('#OtherDiv').hide();
}
});
});
这篇关于jQuery:如果特定的< select>选项被选中了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!