在Drupal 7中没有调用Javascript函数,而Drupal 7曾在Drupal 6中正常运行
Javascript function not getting called in Drupal 7 which used to run proper in Drupal 6
我正在将Drupal 6站点迁移到Drupal 7。因此,我在代码方面遇到了一些问题。我读到的Drupal7中对带有jquery等的javascript的调用有所不同。这是我在Drupal6中看到的页面的图片。在更改下拉框时,它上面的表中会填充属于该下拉框的项目地位这在Drupal 6中运行良好。但在Drupal7中,我看到了这个javascript错误。
这是我的php文件中Dropdown的表单元素。
<? 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,
);
这是JavaScript我已经用Drupal 7 的附加标签修改了它
(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),而不必担心"$"的另一个外部绑定。
相关文章:
- 某些js文件在Drupal中不起作用
- CSS和JS在升级到Drupal站点时失败
- 在Drupal 7中执行$(window).load()和$(window).resize()
- 在Drupal自定义模块中点击3次后,Drupal禁用按钮
- 删除<脚本>标签中的<头部>在所有Drupal 7页中
- 如何使用Ajax在Lightbox中提交Drupal表单
- 阻止Drupal's在表单API中单击按钮后刷新的页面
- 我可以在Drupal 7的jquery脚本中有一个php if语句吗?
- 在 PHP 代码 Drupal 7 中使用drupal_add_js
- 点击按钮并在Drupal 7上保存cookie
- 在 Drupal 8 中附加或包含 js 文件
- Google JSAPI 不会在 Drupal 7 中加载
- 在drupal 7中添加javascript-jquery-and-nacl页面的最佳方法
- 在 Drupal 7 中,如何在模块中添加drupal_add_js
- Drupal 主题自定义 js 不仅在 /user 页面上执行
- 尝试在drupal站点上使用响应式幻灯片,但收到控制台错误
- 在 Drupal 的 CKEditor 4 中添加要链接的属性
- 在Drupal 7中没有调用Javascript函数,而Drupal 7曾在Drupal 6中正常运行
- 如何使drupal函数不区分大小写在drupal 7在PHP和javascript
- Drupal 7在模块中添加jQuery