2

Using flip toggle switch i my not getting alert message when toogle is "off" or "on" in jquery mobile plz help me out

in html5

<select name="toggleswitch1" id="toggleswitch1" data-theme="" data-role="slider">
  <option value="off">Off</option>
  <option value="on">On</option>
</select>

in script

 $(document).bind("pageinit", function () {    
   $("#toggleswitch1").unbind('change').bind('change', function() {
     if ($("#toggleswitch1").val('off').slider('refresh')) {
       alert("off");
     }
     else {
       alert("on");
     }
  });
});   
4

1 回答 1

4

工作示例:http: //jsfiddle.net/39DEK/

$(document).on('pageinit', '#index', function(){ 
    $(document).off('slidestop',"#toggleswitch1").on('slidestop', "#toggleswitch1" ,function() {      
        if ($("#toggleswitch1 option:selected").val() == 'off')  {
            alert("off");
        } else {
            alert("on");
        }
    });
});
于 2013-07-11T07:23:05.193 回答