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
Getting value from toggle switch in jQuery Mobile
提问by user2066880
Super basic question, but I can't figure out why the following code won't work:
超级基本的问题,但我不明白为什么下面的代码不起作用:
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 vclick
instead of tap
or click
. It is a jQuery Mobile event that bridges a mobile and desktop problems with tap/click not working on both platforms.
只需使用vclick
代替tap
或click
。这是一个 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());
});