jQuery点滴细节 保证代码安全
来源:互联网 发布:sql alter 编辑:程序博客网 时间:2024/06/06 09:24
在多人合作开发中一定要确保变量,对象,函数等命名不要冲突:
方法一:当别人使用了其他的js库,并该库使用了”$”变量,那么我们可以使用noConflict()方法:
var j = jQuery.noConflict();
// Now, instead of $, we use j.
j('#someDiv').hide();
// The line below will reference some other library's $ function.
$('someDiv').style.display = 'none';
方法二,把你的代码放在一个匿名函数里面,然后把jQuery作为参数传递给它,那么在这个函数体中的$是不会影响外面或者被外面影响的。
(function($) {
// Within this function, $ will always refer to jQuery
})(jQuery);
方法三,通过ready方法传递$
jQuery(document).ready(function($) {
// $ refers to jQuery
});
// $ is either undefined, or refers to some other library's function.
或者使用简写:
$(function() {
// let's get up in heeya
});
方法一:当别人使用了其他的js库,并该库使用了”$”变量,那么我们可以使用noConflict()方法:
var j = jQuery.noConflict();
// Now, instead of $, we use j.
j('#someDiv').hide();
// The line below will reference some other library's $ function.
$('someDiv').style.display = 'none';
方法二,把你的代码放在一个匿名函数里面,然后把jQuery作为参数传递给它,那么在这个函数体中的$是不会影响外面或者被外面影响的。
(function($) {
// Within this function, $ will always refer to jQuery
})(jQuery);
方法三,通过ready方法传递$
jQuery(document).ready(function($) {
// $ refers to jQuery
});
// $ is either undefined, or refers to some other library's function.
或者使用简写:
$(function() {
// let's get up in heeya
});
0 0
- jQuery点滴细节 保证代码安全
- jQuery技巧:保证你的代码安全
- 使用更少的代码保证 ASP.NET 应用程序的安全
- 使用更少的代码保证 ASP.NET 应用程序的安全
- 使用更少的代码保证 ASP.NET 应用程序的安全
- 合理加锁保持线程代码安全且保证性能
- 技术细节点滴
- 错误、经验、点滴细节
- javascript点滴细节积累
- 点滴编程细节知识
- 每日细节点滴积累
- jquery点滴
- jquery点滴
- 如何保证数据库安全
- VPN如何保证安全
- 如何保证数据库安全
- 240%;">保证网站安全
- 尊重远程,保证安全
- node.js应用Redis初步
- 淄邹坐孜佐拽驻醉咨住左灼浊坠纂阻庄租
- XCode如何添加自定义代码片段
- Android framework——Activity的启动和创建
- 函数构造库
- jQuery点滴细节 保证代码安全
- 查找算法总结——面试(一)
- SyntaxError: identifier starts immediately after numeric literal
- 回归教育本质 培养实用型人才——记杭州年代专修学校
- Xenomai 2.6.4 发布, 支持 Atmel SAMA5D3
- 量初始化列表
- cocos2dx 添加 libiconv.lib 解决 字符转换问题
- uva 1519 Dictionary Size
- 渍综姿嘴着妆转咨谆字钻奏字走足紫纵撞