javascript 如何从第一个未隐藏的复选框中获取价值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11084942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get value from the first checkbox which is not hidden
提问by Mo.
I need to get the value from a checkbox which is not hidden.
我需要从未隐藏的复选框中获取值。
Here is my HTML & JQuery code
这是我的 HTML 和 JQuery 代码
$(document).ready(function() {
var maanu = $('.form').find('input[type=checkbox]:checked').filter(':first').val();
alert(maanu);
});
.hide {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='form'>
<input class="bills hide" type="checkbox" value="01" checked="checked" />
<br />
<input class="bills" type="checkbox" value="02" />
<br />
<input class="bills" type="checkbox" value="03" checked="checked" />
<br />
<input class="bills " type="checkbox" value="04" checked="checked" />
<br />
<input class="bills " type="checkbox" value="05" />
<br />
<input class="bills " type="checkbox" value="06" />
<br />
<input class="bills " type="checkbox" value="07" />
<br />
<input class="bills " type="checkbox" value="08" />
<br />
</div>
回答by Anthony Grist
回答by Zoltan Toth
Try - http://jsfiddle.net/xgQVG/6/
尝试 - http://jsfiddle.net/xgQVG/6/
$(document).ready(function(){
var maanu = $('.form').find('input[type=checkbox]:checked:not(:hidden)').filter(':first').val();
alert(maanu);
});
回答by Justin
Check out this answer. I think it may help you answer your question jQuery If DIV Doesn't Have Class "x"
看看这个答案。我认为它可以帮助你回答你的问题 jQuery If DIV 没有 Class "x"
回答by Jezen Thomas
This works, and is very easy to read and understand:
这是有效的,并且非常容易阅读和理解:
$('input').not('.hide').first().val();