LoginSignup
0
1

More than 5 years have passed since last update.

JQuery Mobileのラジオボタンでハマる

Posted at

JQuery Mobileのラジオボタンでハマる

jQuery-Mobile初心者なのですが、ラジオボタンの値をJSから取得・設定しようとして壮絶にはまったのでメモします。

sample.html
<div class="ui-field-contain">
    <label for="pcschoice">ラジオボタンによる値設定</label>
    <fieldset name="radiochoice" id="radiochoice" data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">
    <input type="radio" name="radiochoice" id="radiochoice1" value="1" />
    <label for="pcschoice1">1</label>
    <input type="radio" name="radiochoice" id="radiochoice2" value="2" />
    <label for="pcschoice2">2</label>
    <input type="radio" name="radiochoice" id="radiochoice3" value="3" />
    <label for="pcschoice3">3</label>
    </fieldset>
</div>
sample.js
$(document).on("pagebeforeshow", "#serialportsetting", function () {
    var p = $('#radiochoise input:radio');
    var s = $('#sensorchoise input:radio');
    for (var i = 0; i < 3; i++) {
        if ($(document).data("sysinfo")['serial']['pcs'] == $(p[i]).val()) {
            $(p[i]).attr("checked", true).checkboxradio("refresh");
        }
        if ($(document).data("sysinfo")['serial']['sensor'] == $(s[i]).val()) {
            $(s[i]).attr("checked", true).checkboxradio("refresh");
        }
    }
});

ポイント

<form>は特に必要ない

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1