Jquery 和 Mootools,.noConflict 失败
我有一个需要使用 mootools 日历的应用程序,但是,我使用 jquery 作为我的主要应用程序结构。
一旦我将 mootools 与 jquery 结合使用,两者都不起作用,而当我只有一个时,它们就可以正常工作。我做了一些研究,说我可以使用一种名为 .noconflict 的方法,虽然我已经尝试过,但我还没有得到它来解决我的问题。也许有人可以更好地向我解释在哪里进行实际的 .noconflict 调用,也许可以帮助我完成这项工作。
谢谢!
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var fixHeight = function () {
var gutter = 50;
var newHeight = $(window).height() - (gutter*2);
$('#container').height(newHeight);
}
$(function(){
fixHeight();
$('ul#nav li.item').each(function(index) {
if ($(this).attr("name") == "media") {
$(this).attr("id","active");
}
});
$('input').focus(function() {
$(this).attr("value","");
}).blur(function() {
$(this).attr("value",$(this).attr("original-value"));
});
$(window).resize(function() {
fixHeight();
}).load(function() {
fixHeight();
});
});
</script>
<script type="text/javascript" src="http://taptouchclick.com/js/mootools-1.2.4-core-yc.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){
var smoothCalendar = new SmoothCalendar("calendar");
});
</script>
I have an application that requires the use of a mootools calendar, however, I use jquery for my main app structure.
As soon as I have mootools in with jquery, neither work, and when I have only one, they work fine. I did some research saying I could use a method called .noconflict, and while i've tried, I have not gotten it to solve my issue. Perhaps someone could better explain to me where to do the actual .noconflict calls, and perhaps help me get this working.
Thanks!
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var fixHeight = function () {
var gutter = 50;
var newHeight = $(window).height() - (gutter*2);
$('#container').height(newHeight);
}
$(function(){
fixHeight();
$('ul#nav li.item').each(function(index) {
if ($(this).attr("name") == "media") {
$(this).attr("id","active");
}
});
$('input').focus(function() {
$(this).attr("value","");
}).blur(function() {
$(this).attr("value",$(this).attr("original-value"));
});
$(window).resize(function() {
fixHeight();
}).load(function() {
fixHeight();
});
});
</script>
<script type="text/javascript" src="http://taptouchclick.com/js/mootools-1.2.4-core-yc.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){
var smoothCalendar = new SmoothCalendar("calendar");
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,
noConflict
方法应该可以工作,但是如果不行或者您想以其他方式执行此操作,则应该将脚本封装在自调用函数中,并将参数设置为 main库对象:之后,您应该包含下一个库(在您的例子中为 MooTools)并正常编写脚本,或者 - 非常确定 - 您也可以将 MooTools 逻辑封装在函数中。
yes, the
noConflict
method should work, but if it doesn't or if you want to do it in another way, you should encapsulate the scripts in self-calling functions with the parameter being set as the main library object:after that, you should include the next library(in your case MooTools) and write the script normally , or - to be very sure - you can encapsulate the MooTools logic in a function as well.
就应该没问题
如果您只需调用: ...在包含 Mootools JS 文件之前
。然后,您可以通过使用
jQuery
而不是$
来使用 jQuery 函数。例子:You should be fine if you simply call:
...before including the Mootools JS file.
You can then use jQuery functions by using
jQuery
instead of$
. Example:您还可以通过 DOM-ready 事件将
$
传回:You can also pass
$
back in through the DOM-ready event: