dongzhiman2162 2014-03-21 00:22
浏览 67

如何将JQuery添加到Joomla 3页面

I am new to Joomla 3.

I am trying to add a JQuery script to a joomla page that runs with the $ sign. In the documentation, I found that I need to add JHtml::_('jquery.framework', false); to do that, but it isn't working.

I tried:

<?php 

JHtml::_('jquery.framework', false);

?>

<div class="text">JQuery is not working</div> 

<script type=text/javascript">

$(document).ready(function(){

$('.text').text("JQUERY ROCKS!");

});
</script>

And the usual:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>    

<div class="text">JQuery is not working</div> 

<script type=text/javascript">

$(document).ready(function(){

$('.text').text("JQUERY ROCKS!");

});
</script>

But none works. Why?

  • 写回答

1条回答 默认 最新

  • dqingn8836 2014-03-21 01:03
    关注

    The problem is your loading jQuery without no conflict mode. Joomla uses another JavaScript library Mootools which also used the $ symbol, which is why it isn't working. I would change your call to:

    JHtml::_('jquery.framework');
    

    And you could either use jQuery instead of $ for all your jQuery methods or wrap your existing code around an Immediately Invoked Function like so:

    (function ($) {
    
         // put your jQuery code here that used $
    
    })(jQuery);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)