JQuery的移动滑块更改事件 [英] Jquery Mobile Slider change event

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

问题描述

我在一个简单的页面上有一个jQuery的移动滑块。当我拖动滑块时,该值在文本框中按预期进行更新。我看过,但无法找到这个逻辑发生的地方。

我想要的是将值传递给javascript函数。如何将变化事件绑定到我的函数?



干杯



Mike。



以下代码 - 请忽略一些讨厌的黑客行为:

 <!DOCTYPE html> 
< html>

< head>
< meta charset =utf-8/>
< title> jQuery Mobile Docs - 表单< / title>
< link rel =stylesheethref =fader / jquery.mobile-1.0a3.css/>
< script type =text / javascriptsrc =fader / jquery-1.5.js>< / script>
< script type =text / javascriptsrc =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;
职位:亲属;
}
.toolbar> h1 {
position:absolute;
overflow:hidden;
剩下: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;
文本溢出:省略号;
white-space:nowrap;
颜色:#fff;
}
.button,.back,.cancel,.add {
position:absolute;
overflow:hidden;
top:8px;
right:10px;
保证金:0;
border-width:0 5px;
padding:0 3px;
width:auto;
height:30px;
line-height:30px;
font-family:inherit;
font-size:12px;
font-weight:bold;
颜色:#fff;
text-shadow:rgba(0,0,0,0.5)0px -1px 0;
文本溢出:省略号;
text-decoration:none;
white-space:nowrap;
背景:无;
-webkit-border-image:url(fader / Resources / Themes / JQT / img / button.png)0 5 0 5;
}
body> * {
background:-webkit-gradient(线性,0%0%,0%100%,从(#1e1f21)到(#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;
颜色:#aaa;
}
h1,h2 {
字体:bold 18px Helvetica;
text-shadow:rgba(255,255,255,.2)0 1px 1px;
颜色:#FFF;
margin:10px 20px 5px;
}
body {
background:#000;
颜色:#ddd;
}
< / style>
< / head>

< body>
< div class =ui-body-adata-role =page>
< div class =toolbar>
< h1>输入< / h1>

< A class =backHREF =javascript:javascript:history.go(-1)>主页< / A

>< DIV>





< form action =#method =get>


< div class =ui-body-adata-role =fieldcontain>

< h1>照明强度< / h1>
< input type =rangename =slider-1id =slider-1value =0min =0max =100data-theme =b track-theme =aorientation =vertical/>



< / div>

< / form>

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

< / body>
< / html>


解决方案

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

 < div id =div-slider> 
< input type =rangeid =slider-1/>
< / div>

您可以在变更时获得一个活动:

  $(#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的移动滑块更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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