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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题