admin管理员组

文章数量:1328798

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

/

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

$(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.

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

http://jsfiddle/2ckHr/3/

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

$(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.

Share Improve this question edited Jul 12, 2013 at 20:12 Pablo 6,0687 gold badges36 silver badges52 bronze badges asked Jul 12, 2013 at 18:48 user2066880user2066880 5,0249 gold badges44 silver badges67 bronze badges 1
  • Changing tap to click makes it work for me. Is there a difference between the two in jQuery Mobile? – ayyp Commented Jul 12, 2013 at 18:51
Add a ment  | 

2 Answers 2

Reset to default 3

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.

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

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

本文标签: javascriptGetting value from toggle switch in jQuery MobileStack Overflow