【问题标题】:Issue with refreshing radio buttons in jquery mobilejquery mobile中刷新单选按钮的问题
【发布时间】:2012-01-11 00:34:40
【问题描述】:

我的问题是我无法刷新单选按钮。我有三个单选按钮,当我第一次单击任何按钮时,它工作正常。但是,当我单击另一个按钮时,它会触发事件,但不会在视觉上更新按钮(前一个按钮仍保持视觉检查)。这是我的代码

  <fieldset data-role="controlgroup">
          <legend>Increment:</legend>
          <input type="radio" name="radiob" id="radio1" value="1" class="radio_button"/>
          <label for="radio1">1</label>
          <input type="radio" name="radiob" id="radio2" value="2" class="radio_button" />
          <label for="radio2">2</label>
          <input type="radio" name="radiob" id="radio3" value="3" class="radio_button" />
          <label for="radio3">3</label>
  </fieldset>

这里是jquery代码

$(".radio_button").change(checkIncrement);

function checkIncrement(){
           $('input:[name=radiob]:radio:checked').checkbox("refresh");
            rd=$('input:[name=radiob]:radio:checked').val();
            inc="i"+rd;
            var ch=1;
            var sl=parseInt(rd)+parseInt(ch);
            $("#slider").attr("min", sl).slider("refresh");   
        }

【问题讨论】:

    标签: jquery jquery-ui jquery-mobile cordova


    【解决方案1】:

    checkIncrement()第一行你使用的方法名不对,应该是checkboxradio

    $('input:[name=radiob]:radio:checked').checkboxradio("refresh")
    

    这里有一个演示 - http://jsfiddle.net/kvhFc/

    【讨论】:

    • 我已经进行了更正,但是现在当我单击第二个按钮时,它会在视觉上更新,但前一个按钮在视觉上保持不变。我认为我们还需要刷新其他按钮(未选中的)。该怎么做?
    • 你能试着注释掉那一行,看看在这种情况下它是如何工作的吗?
    • 在这种情况下,当我点击按钮时,它会触发事件,但当我再次点击它时,它会在视觉上更新。 (点击两次后)
    • 我用您发布的代码创建了一个 jsfiddle,它似乎工作正常。这是链接。jsfiddle.net/kvhFc。您在哪里调用了单选按钮的更改处理程序?请用您编写的方式更新小提琴,以便我可以查看它。
    • 我已经使用了这个代码 $('input:[name=radiob]').checkboxradio("refresh");并且工作正常。谢谢!!!
    【解决方案2】:

    在 Jquery 移动单选按钮中是这样的:

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

    试试这个对我来说很好用

    【讨论】:

      猜你喜欢
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 2011-09-06
      • 2014-03-29
      • 2013-06-12
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多