1

変更時にデバイスの向きを変更する2つのラジオボタンのセットがあります。

私が抱えている問題は、横向きのラジオボタンを選択すると機能しますが、縦向きのラジオボタンを再選択すると、横向きのアラートが表示され、同じままです。

これが私の試みです:

HTML:

<fieldset data-role="controlgroup">
<input type="radio" name="orientation" id="portrait" value="1" checked />
<label for="portrait">Portrait</label>

<input type="radio" name="orientation" id="landscape" value="2" />
<label for="landscape">Landscape Mode</label> 
</fieldset> 

JS:

$("input[name='orientation']").change(function() {
        if ($("input[name='orienation']:checked").val() == '1') {
            navigator.screenOrientation.set('portrait');
            alert('portrait');
        }                
        else if ($("input[name='orienation']:checked").val() == '2') {
            navigator.screenOrientation.set('landscape');
            alert('landscape');
        }
    })

jQueryとjQuery Mobileを使用しています

4

1 に答える 1

2

あなたのif声明はもっと似ているべきです:

if ($(this).val() == '1') {
  ...
}                
else if ($(this).val() == '2') {
  ...
}
于 2012-12-28T18:01:15.763 に答える