jquery selectedIndex 不起作用 [英] jquery selectedIndex doesn't work
本文介绍了jquery selectedIndex 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有许多选择标签的 from ,当用户提交表单时,我想检查用户是否为所有选择标签选择了一个选项,这是我的 jquery 代码
i have a from with many select tags , when the user submit the form i want to check if the user choose one option for all the select tags and this is my jquery code
$('#apForm select').each(function(){
var $this = $(this);
if ($this.selectedIndex == 0){
var error = 'fill this please' ;
$this.next('span').text(error);
errorCount = errorCount + 1;
}
});
我就这样试过
$this.attr("selectedIndex")
我只是给你我的问题所在的一段代码如果我应该提供更多代码,请告诉我
i just give you the piece of my code where my question is if i should give more code tell me
谢谢你的帮助
推荐答案
var $this = $(this);
if($this.get(0).selectedIndex == 0) {
}
或者只是简单
this.selectedIndex; // not $this / $(this)
如果没有option
,它将返回-1
这篇关于jquery selectedIndex 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文