drupal7 不能使用美元符号的原因

本文介绍了一种在Drupal7中确保JavaScript代码不仅限于jQuery库的方法,通过使用闭包来实现与其他JavaScript库的兼容性,避免了全局变量冲突,并提供了一个具体的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Drupal 7 更新文档上写到:

Javascript should be made compatible with other libraries than jQuery by adding a small wrapper around your existing code:

这是为了兼容其他的JAVASCRIPT这样做的,
有一个办法可以解决:

(function ($) { 
// Original JavaScript code. 
})(jQuery);

 

可以使用闭包解决
The $ global will no longer refer to the jquery object. However, with this construction,
the local variable $ will refer to jquery, allowing your code to access jQuery through $ anyway,
while the code will not conflict with other libraries that use the $ global.


(function ($) {
// Create the tooltips only on document load
$(document).ready(function() {
// By suppling no content attribute, the library uses each elements title attribute by default
$('#content a[href]').qtip({
// Simply use an HTML img tag within the HTML string
content: 'dfdfdfdfdf'
});
});
})(jQuery);

 

ebook library

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值