html - 使用翻转切换开关,当切换为 "off"或 "on"时,我没有收到警报消息

标签 html jquery-mobile

使用翻转切换开关,当toogle“关闭”或“打开”时,我没有收到警报消息 在 jquery mobile 中请帮帮我

在 html5 中

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

在脚本中

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

最佳答案

工作示例: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");
        }
    });
});

关于html - 使用翻转切换开关,当切换为 "off"或 "on"时,我没有收到警报消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17587106/

相关文章:

javascript - 重构/改进基本的 JavaScript 练习——将数字分数转换为字母等级

android - 如何在android中使用html href中给出的数据

html - 如何在 jquery mobile 中为可折叠集创建列表分隔符

javascript - 为什么我无法选择列表框值?

c# - 使用 Jquery Mobile 启用/禁用 JQuery 复选框

php - 数据库中的下拉菜单没有结果

c# - 如何从 blazor 中的子项调用父 razor 组件中的函数?

html - 在 bootstrap 中创建响应式 div

javascript - jQuery Mobile - 获取加载的页面 ID?

jquery mobile - 使后退按钮从上一页提交表单?