2015-02-11 70 views
0
<div class="table-thing with-label widget uib_w_114 d-margins" data-uib="app_framework/flip_switch" data-ver="1"> 
    <label class="narrow-control label-inline">Notifications</label> 
    <div class="wide-control"> 
     <input type="checkbox" class="toggle" id="af-flipswitch-1" name="af-flipswitch-1" checked="checked"> 
     <label for="af-flipswitch-1" data-off="Off" data-on="On"> 
      <span></span> 
     </label> 
    </div> 
</div> 

我不知道如何從翻轉開關(開或關)的值,並賦值給一個JavaScript變量。如何獲得從輕觸開關選擇的值或者撥動開關

編輯:上面的代碼是從應用程序設計師(英特爾XDK)

要獲得的值使用,

if ($('#af-flipswitch-1').is(":checked")) 
      { 
    console.log("On"); 
     } else { 
      console.log("Off"); 
      } 

回答

2

翻轉開關的HTML代碼

<label for="flip-1">Flip switch:</label> 
<select name="flip-1" id="flip-1" data-role="slider"> 
    <option value="off">Off</option> 
    <option value="on">On</option> 
</select> 

<button id="submit">Submit</button> 

jQuery代碼

$(document).delegate("#submit", "tap", function() { 
    alert($("#flip-1").val()); 
}); 

Click to Demo

+0

謝謝.. :-) – 2015-02-11 10:44:40