部分响应 Drupal jQuery 脚本
Partially responding Drupal jQuery script
我正在从自定义 Drupal 模块加载一个简单的 jquery 脚本。
浏览器网络数据确认我的脚本已成功加载,但我的简单 点击 检测尝试未被发现。 console.log 消息确实有响应,但没有响应函数。我的代码如下:
(function ($) {
$('body').click( // unresponsive
function(){
alert('responding');
}
);
console.log('Responding'); // this works
jQuery('input#edit-search').click( // unresponsive
function(){
alert('testing ... testing!');
}
);
})(jQuery);
我找到了答案。
Drupal 7 似乎更喜欢以下 jquery 代码格式:
jQuery(document).ready(function($) {
// Code that uses jQuery's $ can follow here.
$('input#edit-search').hide();
});
我正在从自定义 Drupal 模块加载一个简单的 jquery 脚本。
浏览器网络数据确认我的脚本已成功加载,但我的简单 点击 检测尝试未被发现。 console.log 消息确实有响应,但没有响应函数。我的代码如下:
(function ($) {
$('body').click( // unresponsive
function(){
alert('responding');
}
);
console.log('Responding'); // this works
jQuery('input#edit-search').click( // unresponsive
function(){
alert('testing ... testing!');
}
);
})(jQuery);
我找到了答案。
Drupal 7 似乎更喜欢以下 jquery 代码格式:
jQuery(document).ready(function($) {
// Code that uses jQuery's $ can follow here.
$('input#edit-search').hide();
});