基本上,我有一个选择选项,它从数据库中提取所有“旅游名称”作为$ touroptions。$ touroptions可以包含1-20个值(选择选项)中的任何值。
我需要做的是让jQuery函数执行如下操作:
If (any option) #sel-destination-tour is selected {
//DO SOMETHING
}
ELSE {
//DO SOMETHING ELSE
}
我只是不确定我该怎么做。
的HTML
<select name="sel-destination-tour" id="sel-destination-tour" class="input-select-tour">
<option value="0"></option>
<?php echo $touroptions ?>
</select>
您可以通过测试select的value属性来检查选项是否
if($('#sel-destination-tour').val()){
// do something
} else {
// do something else
}
跟踪select的更改事件并相应地处理您的工作
$(function(){
$("#sel-destination-tour").change(function(){
if($(this).val() !="0")
{
// logic goes here
}
else
{
// no option is selected
}
});
});
尝试这个
$('#sel-destination-tour').val() == ""){
//nothing selected;
}else{
//something selected;
}
假设您具有示例中显示的第一项,就可以做到这一点...
if ($("#sel-destination-tour").val() != "0") {
// nothing selected
} else {
// something selected
}
检查val()
(假设0为无值):
if ($('#sel-destination-tour').val() != 0) {
// has a value selected
}
else {
// does not have a value selected
}
示例-http://jsfiddle.net/infernalbadger/RrtT7/
在我的情况下val()
是回国[]
并登场true
。所以我将其更改为:
if($('#sel-destination-tour').val()[0]){
// do something
} else {
// do something else
}
本文地址:http://jquery.askforanswer.com/jquery-jianchashifouxuanzelerenhexuanzexuanxiang.html
文章标签:jquery
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!
文章标签:jquery
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!
评论已关闭!