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

查看:25
本文介绍了如何使用 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-->

我创建了一个 Fiddle 来演示.如果您转到 link,然后单击启用了 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天全站免登陆