0

jQuery:

这是我编辑的 jquery:

$(document).ready(function(){
    $("#set-button").click(function(){
        $("#radio-choice-a").attr("checked", "checked");
        counter=aRoute;
        $('#data-scroller').scroller('destroy');
        scroller();     
    });
});

html: 已编辑

<div data-role="fieldcontain">
      <fieldset data-role="controlgroup" data-type="horizontal">
              <input type="radio" name="radio-choice" id="radio-choice-a"
              value="on" checked="checked" /> <label for="radio-choice-a">A</label>
               <input type="radio" name="radio-choice" id="radio-choice-b"
               value="off" /> <label for="radio-choice-b">B</label> 
               <input type="radio" name="radio-choice" id="radio-choice-c"
           value="other" /> <label for="radio-choice-c">C</label>
       </fieldset>
</div>
<a href="#" id="set-button" data-theme="a">Set</a>

有谁知道怎么做?

4

5 回答 5

1

伙计们,我用过这个,它奏效了。它之前不起作用的原因是因为我使用的是 jquery.mobile-1.1.1 javascript 文件。因此需要刷新以更新视觉样式。

 $("#radio-choice-a").attr("checked",true).checkboxradio("refresh");
于 2012-08-14T23:19:23.630 回答
0

http://jsfiddle.net/9y5na/

You might as well just search by that ID if that's the specific one you want. Use .prop('checked', true); and you're all set. Also radio-choice-a already has checked="checked" within it, why it might seem like the JS isn't doing anything!

$("#radio-choice-a").prop("checked", true);​
于 2012-08-14T18:45:52.053 回答
0

You can simply do this:

$("#radio-choice-a").attr("checked", "checked");​
$("#buttonSetSelector").buttonset("refresh");    //If you are using a buttonset

$("#radio-choice-a").button("refresh");   // If you are just using buttons

See this fiddle for an example: http://jsfiddle.net/johnkoer/SLqWG/4/

于 2012-08-14T18:45:57.963 回答
0

You can select the elements by their IDs, also you can use the prop method for modifying the checked property of the inputs:

$(document).ready(function() {
    $('#radio-choice-a').prop('checked', true)
    $('#radio-choice-b').prop('checked', false)
})
于 2012-08-14T18:46:13.730 回答
0
document.getElementById('radio-choice-a')​​​​.checked=true;​

小提琴

于 2012-08-14T19:01:19.600 回答