【问题标题】:JQuery is not working because Mootools is already loaded in joomlaJQuery 不工作,因为 Mootools 已经在 joomla 中加载
【发布时间】:2011-09-06 18:54:25
【问题描述】:

我尝试将 JQuery 库包含到 joomla 中,但它不起作用。许多组合和模块在我的 CMS 中使用 mootools。我认为问题是两个框架之间的冲突。

我在网上搜索了一些文章,但是下面的代码仍然没有按预期工作。

<?php
JHTML::stylesheet('demo_page.css', 'media/system/css/');
JHTML::stylesheet('ftab.css', 'media/system/css/');
JHTML::stylesheet('demo_table.css', 'media/system/css/');
$option="com_mycomp";
$base=JUri::root().'components/'.$option.'/js/';
$document=&JFactory::getDocument();
$noConflict="jQuery.noConflict();";
//$document->addScriptDeclaration($noConflict);
$document->addScriptDeclaration("jQuery(document).ready(function($){jQuery('#example').dataTable();});");
JHTML::script('jquery.js',$base,true);
$document->addScript($base,'jquery.js');
$document->addScript($base,'jquery.dataTables.js');
?>

这应该使用 JQuery 对我的表进行排序,但它没有。

如何在 joomla 中同时使用 mootools 和 jQuery?

提前感谢您的帮助!

【问题讨论】:

    标签: javascript jquery mysql frameworks mootools


    【解决方案1】:

    阅读您的代码,我看到了:

    $noConflict="jQuery.noConflict();";
    //$document->addScriptDeclaration($noConflict);
    $document->addScriptDeclaration("jQuery(document).ready(function($){jQuery('#example').dataTable();});");
    JHTML::script('jquery.js',$base,true);
    $document->addScript($base,'jquery.js');
    $document->addScript($base,'jquery.dataTables.js');
    

    但它应该是这样的:

    JHTML::script('jquery.js',$base,true);
    $document->addScript($base,'jquery.js');
    $document->addScript($base,'jquery.dataTables.js');
    $noConflict="jQuery.noConflict();";
    //$document->addScriptDeclaration($noConflict);
    $document->addScriptDeclaration("jQuery(document).ready(function($){jQuery('#example').dataTable();});");
    

    现在,原因如下:

    Javascript 是按照它进入页面的顺序来解释的。页面被告知使用 jQuery.noConflict() 和 jQuery 数据表,然后才知道这些东西是什么。

    【讨论】:

    • 非常感谢@jcolebrand!它真的帮助我解决了这个问题!
    • 然后我discommmented //$document-&gt;addScriptDeclaration($noConflict); line
    • 另外,您能否告诉我如何使用 JHTML 在 joomla 中为 标签添加属性。我需要改变它的类&lt;body id="dt_example" class="ex_highlight_row"&gt;
    • 两个 cmets:我不太了解 Joomla,无法知道如何告诉你,但是一旦页面加载,jQuery 可以很容易地做到这一点(只有一个 标签).. . 如果答案对你有帮助,请看这里:meta.stackexchange.com/questions/5234/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 2011-03-05
    • 2014-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多