在Drupal 6中,用于在Drupal 6中正常运行的Javascript函数没有被调用 [英] Javascript function not getting called in Drupal 7 which used to run proper in Drupal 6

查看:607
本文介绍了在Drupal 6中,用于在Drupal 6中正常运行的Javascript函数没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Drupal 6站点迁移到Drupal 7.因此,我在代码中遇到一些问题。
在Drupal 7中调用javascript与jquery等不同是我读过的。
这是我在Drupal 6中的页面的图像。
在更改下拉框时,上表列出了属于该
状态的项目。这在Drupal 6中工作正常。
但是在Drupal 7中,我看到这个javascript错误。 / a>



这是我的php文件中的下拉菜单的表单元素。

 code>< ;? php 
$ form ['status_list'] = array(
'#type'=>'select',
'#title'=> t('高速公路项目状态'),
'#options'=>数组(
0 => t(' - 选择状态 - '),
1 => t('Draft'),
2 => t('NotSpecified'),
3 => t('Quote'),
4 => t('Forecasted'),
5 => ('InEvaluation'),
6 => t('Cancelled'),
7 => t('Booked'),
8 => t('InProduction' ,
9 => t('Completed'),
10 => t('Closed'),
),
'#default_value'=& '0'=>'选择状态'),
'#weight'=> 0,
);

这是JavaScript
我已经修改了与Drupal 7的附加标签

 (function $){..})(jQuery); 。 

Drupal 6中不需要这些标签。



($($)$($)$($)$($)$($) ();
var charExists =((window.location.href).indexOf('?')。 > = 0)?true:false;

if(charExists){
var split =(window.location.href).split('?');
var loc = split [0];

loc = loc +status =+ selectedStatus;
self.location.href = loc;

}

else {
var locf = window.location.href +?status =+ selectedStatus;
self.location.href = locf;

} $ b提交(function(){
$(:submit,this).attr(
$ b});

$(#create-highway-project (disabled,disabled);

});

$(。common_link_class)点击(function(){
// alert (你好) ;

var count =($(this).data(clicks)|| 0)+ 1;
$(this).data(clicks,count);


if($(this).data(clicks)> = 1){

}


if($(this).data(clicks)> = 2){

return false;
}
});


$(#edit-analysis-code-one)。change(function(){
//获取配置并拆分它们
var cfgs = _get_configs(edit-custRef);
var split_cfgs = cfgs.split('/');

//创建一些新的配置并将其放回到配置文本域中。
// var new_cfgs = $(this).val()+/+ cfgs [1];
var new_cfgs = $(#edit-analysis-code-one option:selected .text()+/+ cfgs [1];

$(#edit-custRef)。val(new_cfgs);
});

$(#edit-analysis-code-two)。change(function(){
//获取配置并拆分它们
var cfgs = _get_configs edit-custRef);
var split_cfgs = cfgs.split('/');

//创建一些新的配置并将其放回到配置文本框中
// var new_cfgs = cfgs [0] +/+ $(this).val();
var new_cfgs = cfgs [0] +/+ $(#edit-analysis-code-two选项:selected)。text()
$(#edit-custRef)。val(new_cfgs);
});


});

})(jQuery);


(function $){
函数_get_configs(id){

返回$(#+ id).val();

}
})(jQuery);

#edit_status_list 是我们的兴趣下拉菜单。



想要就Drupal 7中适当的javascipt调用需要做什么额外的更改?

解决方案

应该是

 (function($){

 函数$ {

你所得到的是一个语法错误,第一个实例化一个函数,它的第一个参数将通过其身体代码中的符号 $ 提供。该函数在正文后调用:

  // ... 
})(jQuery);

和全局jQuery对象作为参数传入,此设置通过常用的$符号确保您的代码访问正确的框架(即jQuery),而无需担心另一个外部绑定为$。


I am in the process of migrating my Drupal 6 site to Drupal 7. As a result i am facing some issues with the code. The calling of javascript laced with jquery etc is different in Drupal 7 is what i have read. This is the image of the page i had in Drupal 6. On change of the dropdown box, the table above it gets populated with projects belonging to that status. This works fine in Drupal 6. But in Drupal 7 i see this javascript error.

This is the form element for the Dropdown in my php file.

<? php
 $form['status_list'] = array(
'#type' => 'select',
'#title' => t('Freeway Project Statuses'),
'#options' => array(
  0 => t('-Select Status-'),
  1 => t('Draft'),
  2 => t('NotSpecified'),
  3 => t('Quote'),
  4 => t('Forecasted'),
  5 => t('InEvaluation'),
  6 => t('Cancelled'),
  7 => t('Booked'),
  8 => t('InProduction'),
  9 => t('Completed'),
  10 => t('Closed'),
 ),
 '#default_value' => array('0' => 'Select Status'),
 '#weight' => 0,
);

And this is the JavaScript I have modified it with the additional tags for Drupal 7

 (function$){ .. })(jQuery); . 

These tags were not needed in Drupal 6.

      (function$){
    $(document).ready(function () {
     $("#edit-status-list").change(function() {
     var selectedStatus = $(this).find(":selected").text();
     var charExists = ((window.location.href).indexOf('?') >= 0) ? true : false;

    if(charExists){
    var split = (window.location.href).split('?');
    var loc = split[0];

      loc = loc+"?status="+selectedStatus;  
    self.location.href= loc;

    }

    else{
     var locf = window.location.href+"?status="+selectedStatus;   
     self.location.href= locf;

     }

     });

     $("#create-freeway-project").submit(function() {
      $(":submit", this).attr("disabled", "disabled");

     });

    $(".common_link_class").click(function() {
          //alert("Hello");

       var count = ($(this).data("clicks") || 0) + 1;
       $(this).data("clicks", count);


        if ($(this).data("clicks") >= 1) {

       }


       if ($(this).data("clicks") >= 2) {

         return false;
       }
     });


      $("#edit-analysis-code-one").change(function () {
        // Get the configs and split them.
        var cfgs = _get_configs("edit-custRef");
        var split_cfgs = cfgs.split('/');

        // Create some new configs and put it back into the configs  textfield.
        //var new_cfgs = $(this).val() +"/"+ cfgs[1];
        var new_cfgs = $("#edit-analysis-code-one option:selected").text() +"/"+ cfgs[1];

        $("#edit-custRef").val(new_cfgs);
      });

      $("#edit-analysis-code-two").change(function () {
        // Get the configs and split them.
        var cfgs = _get_configs("edit-custRef");
        var split_cfgs = cfgs.split('/');

        // Create some new configs and put it back into the configs textfield.
        //var new_cfgs = cfgs[0] +"/"+ $(this).val();
        var new_cfgs = cfgs[0] +"/"+ $("#edit-analysis-code-two option:selected").text()
        $("#edit-custRef").val(new_cfgs);
     });


   });

 })(jQuery); 


(function$){
function _get_configs(id) {

  return $("#"+ id).val();

}   
})(jQuery); 

#edit_status_list is the dropdown of our interest.

Would like to have your suggestions as to what additional change needs to be done for proper javascipt calling in Drupal 7

解决方案

It should be

(function($) {

Not

(function$ {

What you've got is a syntax error. The first one instantiates a function such that its first argument will be available via the symbol $ in its body code. The function is invoked after the body:

  // ...
})(jQuery);

and the global "jQuery" object is passed in as the argument. This setup assures your code access to the correct framework (that is, to jQuery) via the common "$" symbol without having to worry about another external binding for "$".

这篇关于在Drupal 6中,用于在Drupal 6中正常运行的Javascript函数没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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