douwen1901 2014-08-07 10:58
浏览 62
已采纳

Jquery UI滑块事件不起作用Drupal 7

I am trying to implement a slider for a view form ( i have hidden the text field and want to make a script to display a slider and on change / stop to set the value to hidden text field. My problem is that the events are not firing at all. I added the jquery UI library and my script in the template.php of my template ( using ZEN ) :

function ThemeName_preprocess_page(&$variables) {
  drupal_add_library('system', 'ui');
  drupal_add_library('system', 'ui.slider');
  drupal_add_js('URL/js/search.js');
}

and this is the javascript/jquery code :

(function ($, Drupal, window, document, undefined) {
  Drupal.behaviors.customSearch = {
    attach: function(context, settings) {
        $(document).ready(function (){
          $("#distanta_slider").slider({
                orientation: "horizontal",
                range: "min",
                max: 150,
                min: 1,
                value: 1,
                //change: slider_change(),
                //slide: slider_change(),
                //stop: slider_change()
            });
            $("#distanta_slider").on("slidestop",slider_change());
            $("#distanta_slider").on("slide",slider_change());
            $("#distanta_slider").on("slidechange",slider_change());
            });
        function slider_change(){
            alert($("#distanta_slider").slider("value"));
        }
      }
  };
})(jQuery, Drupal, this, this.document);

I tried binding the event using $(selector).on , and also tried to declare them in the constructor ( the 3 commented lines ). In the first scenario at page load i received 3 alerts with the current value , in the second scenario i receive 3 alerts saying "Object Object" , but in both scenarios if I move the slider absolutely nothing happens ... No errors , nothing .

Any help is most appreciated. Thank you in advance,

Cristi

  • 写回答

1条回答 默认 最新

  • dousi1097 2014-08-07 11:05
    关注

    Call function name without arguments in on statement.

     $("#distanta_slider").on("slidestop",slider_change);
     $("#distanta_slider").on("slide",slider_change);
     $("#distanta_slider").on("slidechange",slider_change);
    

    Wrong Assumption

    $("#distanta_slider").on("slidestop",slider_change());
    

    the function slider_change executes immediately here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动