jQuery中未选中单选按钮 [英] Radio buttons not checked in jQuery

查看:67
本文介绍了jQuery中未选中单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这行代码可用于页面加载:

I have this line of code for page load:

if ($("input").is(':checked')) {

和当无线电按钮输入被选中它工作正常.但是,我要相反.类似于

and it works fine when the radio button input is checked. However, I want the opposite. Something along the lines of

if ($("input").not(.is(':checked'))) {

,以便在未选择任何单选按钮时运行if语句.最好的方法是什么?

so that my if statement runs when none of the radiobuttons are selected. What is the best way to go about this?

推荐答案

if ( ! $("input").is(':checked') )

不行吗?

您也可以尝试遍历这样的元素:

You might also try iterating over the elements like so:

var iz_checked = true;
$('input').each(function(){
   iz_checked = iz_checked && $(this).is(':checked');
});
if ( ! iz_checked )

这篇关于jQuery中未选中单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆