检查单选按钮是否存在jQuery [英] Check if radio button exists jQuery

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

问题描述

我根据某个值将单选按钮的选中状态设置为true;

I am setting a radio button's checked state to true based on a certain value;

 var radioValue = data.Activity.Answer == "Please add your answer" ? "valueA" : data.Activity.Answer;
$("input[name=optionRadio" + currentIndex + "][value=" + radioValue + "]").attr('checked', true);

我最好的方法是检查幻灯片上的单选按钮是否真的存在于手中?

What will be the best way for me to check that that radio button actually exists on the slide before hand?

推荐答案

您可以查看要查找的jQuery对象的长度它出来了:

You can check the length of the jQuery object to find it out:

if($("input[name=optionRadio" + currentIndex + "]").length > 0 ){
     // Radio button actually exists...
}

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

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