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 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿