简体   繁体   English

如何从翻转开关或拨动开关中获取选定的值

[英]How to get selected value from a Flip Switch or Toggle Switch

<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>

I am not sure how to get the value from the flip switch (On or Off) and assign to a javascript variable. 我不确定如何从翻转开关(打开或关闭)获取值并将其分配给javascript变量。

Edit: The above code is from App Designer (Intel XDK) 编辑:上面的代码来自应用设计器(Intel XDK)

To get the value use, 为了获得价值,

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

flip switch html code 轻触开关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 code jQuery代码

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

Click to Demo 点击演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM