如果单选框是唯一显示的,则自动选中它
因此,我有以下形式的单选框
<li><input type="radio" name="names" value="blah"><a>Some text (blah)</a></li>
There are 100 plus of such radio Buttons.
现在,我有一个 jQuery 过滤器,来自此处。过滤器工作良好。
但是,我想设置一个 jQuery 语句,如果单选按钮是显示的单选按钮中唯一剩下的,则该语句将自动选择该单选按钮。
该过滤器使用 show()
和 hide()
,我认为这意味着它将其从 display: block 切换到 display: none;
我自己做这件事的最佳方法看起来像这样,但它不起作用:
if($('li').attr({"display":"block"}).size()==1)
{
$('input[cvs_name]:eq(1)').attr('checked', 'checked');
}
我怎样才能做到这一点?
So, I have radio boxes of the form
<li><input type="radio" name="names" value="blah"><a>Some text (blah)</a></li>
There are 100 plus of these radio buttons.
Now, I have a jQuery filter, from here. The filter works well.
But, I want to set a jQuery statement that will auto select the radio button if it is, amongst the shown, the only one remaining.
The filter uses show()
and hide()
, which I presume means it switches it from display: block to display: none;
My best crack at doing this on my own looks like this, but it's not working:
if($('li').attr({"display":"block"}).size()==1)
{
$('input[cvs_name]:eq(1)').attr('checked', 'checked');
}
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
jQuery 有一个
visible
过滤器,它只选择元素哪些不是隐藏的。 (当然,还有一个hidden
过滤器,用于选择那些哪些是。)Try this:
jQuery has a
visible
filter which only selects elements which aren't hidden. (And, of course, ahidden
filter which selects those which are.)