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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看