Jquery Mobile Slider 更改事件 [英] Jquery Mobile Slider change event

查看:19
本文介绍了Jquery Mobile Slider 更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个简单的页面上有一个 jquery 移动滑块.当我拖动滑块时,文本框中的值会按预期更新.我已经看过了,但找不到这个逻辑发生的地方.

我想要的是将值传递给一个 javascript 函数.如何将更改事件绑定到我的函数?

干杯

迈克.

下面的代码 - 请忽略一些讨厌的黑客:

<头><meta charset="utf-8"/><title>jQuery Mobile 文档 - 表单</title><link rel="stylesheet" href="fader/jquery.mobile-1.0a3.css"/><script type="text/javascript" src="fader/jquery-1.5.js"></script><script type="text/javascript" src="fader/jquery.mobile-1.0a3.js"></script><脚本>$('#slider-1').changed(function () {警报(测试");});<style type="text/css">.工具栏{-webkit-box-sizing: 边框框;边框底部:1px 实心 #000;填充:10px;高度:45px;背景: url(fader/Resources/Themes/JQT/img/toolbar.png) #000000 repeat-x;位置:相对;}.工具栏>h1{位置:绝对;溢出:隐藏;左:50%;顶部:10px;行高:1em;边距:1px 0 0 -75px;高度:40px;字体大小:20px;宽度:150px;字体粗细:粗体;文本阴影:rgba(0, 0, 0, 1) 0 -1px 1px;文本对齐:居中;文本溢出:省略号;空白:nowrap;颜色:#fff;}.button, .back, .cancel, .add {位置:绝对;溢出:隐藏;顶部:8px;右:10px;边距:0;边框宽度:0 5px;填充:0 3px;宽度:自动;高度:30px;行高:30px;字体系列:继承;字体大小:12px;字体粗细:粗体;颜色:#fff;文本阴影:rgba(0, 0, 0, 0.5) 0px -1px 0;文本溢出:省略号;文字装饰:无;空白:nowrap;背景:无;-webkit-border-image: url(fader/Resources/Themes/JQT/img/button.png) 0 5 0 5;}身体 >* {背景:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#1e1f21), to(#272729));}.背部 {左:6px;右:自动;填充:0;最大宽度:55px;边框宽度:0 8px 0 14px;-webkit-border-image: url(fader/Resources/Themes/JQT/img/back_button.png) 0 8 0 14;}.back.active {-webkit-border-image: url(Fader%20Test%20-%20Trade%20show/img/back_button_clicked.png) 0 8 0 14;颜色:#aaa;}h1, h2 {字体:粗体 18px Helvetica;文本阴影:rgba(255, 255, 255, .2) 0 1px 1px;颜色:#FFF;边距:10px 20px 5px;}身体 {背景:#000;颜色:#ddd;}</风格><身体><div class="ui-body-a" data-role="page"><div class="工具栏"><h1>输入</h1><A class="back" HREF="javascript:javascript:history.go(-1)">首页</A></div><form action="#" method="get"><div class="ui-body-a" data-role="fieldcontain"><h1>光照强度</h1><input type="range" name="slider-1" id="slider-1" value="0" min="0" max="100" data-theme="b" data-track-theme=a"方向=垂直"/>

</表单></div><!--/content --></div><!--/page -->

解决方案

Michael.尝试用另一个元素包围滑块:

<input type="range" id="slider-1"/>

你可以得到一个关于变化的事件:

$("#div-slider").change(function() {var slider_value = $("#slider-1").val();//做一点事..});

I have a jquery mobile slider on a simple page. When I drag the slider, the value updates as expected in the textbox. I have looked but cannot find where this logic is happening.

What I would like, is to pass the value into a javascript function. How can I bind the change event to my function?

Cheers

Mike.

Code below - please ignore some nasty hacks:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title>jQuery Mobile Docs - Forms</title>
        <link rel="stylesheet" href="fader/jquery.mobile-1.0a3.css" />
        <script type="text/javascript" src="fader/jquery-1.5.js"></script>
        <script type="text/javascript" src="fader/jquery.mobile-1.0a3.js"></script>
        <script>
            $('#slider-1').changed(function () {
                alert("Test");
            });
        </script>
        <style type="text/css">
            .toolbar {
                -webkit-box-sizing: border-box;
                border-bottom: 1px solid #000;
                padding: 10px;
                height: 45px;
                background: url(fader/Resources/Themes/JQT/img/toolbar.png) #000000 repeat-x;
                position: relative;
            }
            .toolbar > h1 {
                position: absolute;
                overflow: hidden;
                left: 50%;
                top: 10px;
                line-height: 1em;
                margin: 1px 0 0 -75px;
                height: 40px;
                font-size: 20px;
                width: 150px;
                font-weight: bold;
                text-shadow: rgba(0, 0, 0, 1) 0 -1px 1px;
                text-align: center;
                text-overflow: ellipsis;
                white-space: nowrap;
                color: #fff;
            }
            .button, .back, .cancel, .add {
                position: absolute;
                overflow: hidden;
                top: 8px;
                right: 10px;
                margin: 0;
                border-width: 0 5px;
                padding: 0 3px;
                width: auto;
                height: 30px;
                line-height: 30px;
                font-family: inherit;
                font-size: 12px;
                font-weight: bold;
                color: #fff;
                text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0;
                text-overflow: ellipsis;
                text-decoration: none;
                white-space: nowrap;
                background: none;
                -webkit-border-image: url(fader/Resources/Themes/JQT/img/button.png) 0 5 0 5;
            }
            body > * {
                background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#1e1f21), to(#272729));
            }
            .back {
                left: 6px;
                right: auto;
                padding: 0;
                max-width: 55px;
                border-width: 0 8px 0 14px;
                -webkit-border-image: url(fader/Resources/Themes/JQT/img/back_button.png) 0 8 0 14;
            }
            .back.active {
                -webkit-border-image: url(Fader%20Test%20-%20Trade%20show/img/back_button_clicked.png) 0 8 0 14;
                color: #aaa;
            }
            h1, h2 {
                font: bold 18px Helvetica;
                text-shadow: rgba(255, 255, 255, .2) 0 1px 1px;
                color: #FFF;
                margin: 10px 20px 5px;
            }
            body {
                background: #000;
                color: #ddd;
            }
        </style>
    </head>

    <body>
        <div class="ui-body-a" data-role="page">
            <div class="toolbar">
                 <h1>Input</h1>

                 <A class="back" HREF="javascript:javascript:history.go(-1)">Home</A

                    ></div>





  <form action="#" method="get">


            <div class="ui-body-a" data-role="fieldcontain">

              <h1>Lighting Intensity</h1>
              <input type="range" name="slider-1" id="slider-1" value="0" min="0" max="100" data-theme="b" data-track-theme="a" orientation="vertical" />



            </div>

    </form>

    </div><!-- /content -->
</div><!-- /page -->

</body>
</html>

解决方案

Michael. Try to surround the slider with another element:

<div id="div-slider">
  <input type="range" id="slider-1" />
</div>

And you can get an event on change:

$("#div-slider").change(function() {
  var slider_value = $("#slider-1").val();
  // do something..
});

这篇关于Jquery Mobile Slider 更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆