jquery - 将jquery函数添加到Joomla模板中

标签 jquery joomla joomla2.5

我试图将 jquery 函数添加到 Joomla 模板,但它不起作用

我添加:

$doc->addScript( "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" );
$doc->addCustomTag( '<script type="text/javascript">jQuery.noConflict();</script>' );

然后是 div:

<div id="row" style="height: 350px; overflow: hidden;" ></div>

和jquery函数:

<script>
    $(document).ready(function(){
    $("#row").click(function(){
        $(this).hide();
    });
    });
</script> 

但是还是不行

请帮助我

提前致谢

最佳答案

由于您处于 noConflict 模式(您真的需要它吗?),因此不再有可用的 $ 别名函数。您需要坚持使用 jQuery 名称:

jQuery(document).ready(function() {
    jQuery("#row").click(function() {
        jQuery(this).hide();
    });
});

或者将您的代码包装到闭包中,并将 $ 作为参数传递

(function($) {
    // now you can use $ symbol as alias to jQuery
})(jQuery);

关于jquery - 将jquery函数添加到Joomla模板中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28392523/

相关文章:

javascript - 在 jQuery.ajax 中指定 OpenCalais SemanticProxy 服务的回调

Joomla ACL : Only allow access to custom component in the backend?

joomla - $input->getCmd ('task' ) JOOMLA 中的 'task' 是什么

javascript - 无法从 $.post 调用返回的 jqXHR 中获取状态代码

jquery - jqgrid 内联编辑,并使用编辑规则在网格中进行验证

php - 想要更改 Joomla 组件名称

php - 子目录需要重新安装Joomla吗?

php - 如何从virtualmart类别表中获取数据?

javascript - 使用 jQuery 突出显示并选择输入的文本

joomla - 如何在 Joomla 2.5 中添加类别