在Drupal 7中没有调用Javascript函数,Drupal 7曾经在Drupal 6中正常运行

我正在将Drupal 6站点迁移到Drupal 7.因此,我遇到了代码的一些问题。 使用jquery等的javascript调用在Drupal 7中是不同的,这是我读过的。 这是我在Drupal 6中的页面图像。在更改下拉框时,上面的表格会填充属于该状态的项目。 这在Drupal 6中运行良好。但是在Drupal 7中我看到了这个javascript错误。

这是我的php文件中Dropdown的表单元素。

 '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, ); 

这是我用Drupal 7的附加标签修改它的JavaScript

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

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是我们感兴趣的下拉列表。

想有关于在Drupal 7中正确进行javascipt调用需要做些什么更改的建议

它应该是

 (function($) { 

 (function$ { 

你得到的是语法错误。 第一个实例化一个函数,使其第一个参数可以通过其体代码中的符号$获得。 该函数在正文后调用:

  // ... })(jQuery); 

并且全局“jQuery”对象作为参数传入。 此设置通过公共“$”符号确保您的代码访问正确的框架(即jQuery),而不必担心“$”的另一个外部绑定。