如何使用JQuery Mobile在不可见的div页面中设置单选按钮? [英] How to set radio buttons in non visible div pages with JQuery Mobile?

查看:133
本文介绍了如何使用JQuery Mobile在不可见的div页面中设置单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html文件,并使用div分成了多个页面.在每个页面上,我都有一个单位切换单选按钮,在按下该按钮时,我希望不可见页面上的所有相应单选按钮也能切换.

I have a single html file split into multiple pages with divs. On each page I have a units toggle radio buton, which on pressing I would like all the corresponding radio buttons on the non visible pages to toggle as well.

我尝试使用以下代码,该代码对于可见页面效果很好,但是在尝试设置不可见单选按钮(a2和b2)时抛出以下错误;

I've tried with the below code, which works well for the page visible, but throws the following error when it tries to set the non visible radio button (a2 and b2);

错误:初始化前无法在checkboxradio上调用方法;尝试调用方法刷新"

Error: cannot call methods on checkboxradio prior to initialization; attempted to call method 'refresh'

代码示例;

    <fieldset data-role="controlgroup" data-type="horizontal" >
<input type="radio" align="center" name="radio-view1" id="radio-view-a1" checked="checked">
<label for="radio-view-a1">Imperial</label>
<input type="radio" name="radio-view1" id="radio-view-b1">
<label for="radio-view-b1">Metric</label>
    </fieldset>

    <!--script type="text/javascript" language="javascript">

$('#radio-view-a1').click(function(){       
    $('#radio-view-a1').attr('checked',true).checkboxradio("refresh");
    $('#radio-view-b1').attr('checked',false).checkboxradio("refresh");
    $('#radio-view-a2').attr('checked',true).checkboxradio("refresh");
    $('#radio-view-b2').attr('checked',false).checkboxradio("refresh");
    updown_toggle_units2imperial();
    });
$('#radio-view-b1').click(function(){
    $('#radio-view-a1').attr('checked',false).checkboxradio("refresh");
    $('#radio-view-b1').attr('checked',true).checkboxradio("refresh");
    $('#radio-view-a2').attr('checked',false).checkboxradio("refresh");
    $('#radio-view-b2').attr('checked',true).checkboxradio("refresh");
    updown_toggle_units2metric();
            });
   </script-->

我创建了一个小提琴来演示.如果您转到链接,然后在激活了Firebug或类似功能的情况下,单击Metric按钮,则可以看到错误消息

I've created a Fiddle to demonstrate. If you go to link, and click on the Metric button with firebug or similar activated, you can see the error message

我们将不胜感激,帮助我理清如何实现理想的行为!

Any assistance to help me sort out how to achieve the desired beviour would be much appreciated!

谢谢

推荐答案

以下组合有效:

$("input[type='radio']").checkboxradio();
$("input[type='radio']").checkboxradio("refresh");

在此处查看工作示例

此链接帮助我找到了出来

这篇关于如何使用JQuery Mobile在不可见的div页面中设置单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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