javascript 从 jQuery Mobile 中的切换开关获取价值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17621990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 08:59:50  来源:igfitidea点击:

Getting value from toggle switch in jQuery Mobile

javascriptjqueryhtmljquery-mobile

提问by user2066880

Super basic question, but I can't figure out why the following code won't work:

超级基本的问题,但我不明白为什么下面的代码不起作用:

http://jsfiddle.net/2ckHr/3/

http://jsfiddle.net/2ckHr/3/

HTML

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>

JS

JS

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

Returns Uncaught TypeError: Cannot call method 'call' of undefined (jquery.mobile-1.3.0-beta.1.js:2823)when submit is pressed.

Uncaught TypeError: Cannot call method 'call' of undefined (jquery.mobile-1.3.0-beta.1.js:2823)按下提交时返回。

采纳答案by Gajotres

Just use vclickinstead of tapor click. It is a jQuery Mobile event that bridges a mobile and desktop problems with tap/click not working on both platforms.

只需使用vclick代替tapclick。这是一个 jQuery Mobile 事件,它通过点击/点击在两个平台上都不起作用来桥接移动和桌面问题。

Working example: http://jsfiddle.net/2ckHr/9/

工作示例:http: //jsfiddle.net/2ckHr/9/

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

回答by kevskree

$('#submit').on("click", function() {
    alert($("#flip-1").val());
});