如何让外部.js文件在joomla中工作
How to get external .JS files to work in joomla
我正在创建一个新的Joomla模板,并且遇到了链接到外部.js文件的问题。
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/main.css">
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/FLpresentation.css">
<script src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/js/jquery-2.1.4.js"></script>
<script src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/js/FLpresentation.js"></script>
<script src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/js/FLajax.js"></script>
上面的代码包含在head标签中,当我将模板安装到joomla中时,CSS工作正常。一切看起来应该如何,但我所有的Jquery和Javascript代码不工作。唯一这样做的代码是在index.php文件的标记内。
谁能告诉我我做错了什么?我已经在templateDetails.xml中定义了文件和文件夹,除了js之外的一切都工作得很好,尽管我使用了完全相同的方法来链接CSS。100% JS冲突。检查一下控制台!虽然包含了Jquery库,但Joomla已经自带了Jquery。检查控制台是否有错误,检查Jquery在输出HTML中是否超过1次,并迁移代码。
也像这样包装你的代码:
(function($) {
$(document).ready(function(){
// START HERE FOR ON_DOCUMENT_READY
alert(1);
});
})(jQuery);
使用JHtml::script方法,如下例所示:
$url = Juri::base();// pick the url for my joomla website
JHtml::script($url . 'components/com_revista/prefixfree.min.js');//here i'm using one file in my server, but you could put the url for your script like
"JHtml::script('http://urlforscriptsource/script.js');"
下面的代码为您的joomla扩展添加JQuery框架:
JHtml::_('jquery.framework');
JHtml::_('jquery.ui');
JHtml::_('jquery.ui', array('sortable'))
;
Ps:在你的JQuery代码中最好使用JQuery()而不是$(),这将避免冲突!
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- javascript没有´我不能在joomla 3.0中工作
- 当代码放在Joomla文章中时,Jquery拖放在Chrome浏览器中无法正常工作
- 为什么我的内容在从 1.5.26 迁移后两次可见,而 JavaScript 在 Joomla 3.x 上无法正常工作
- 修改后的Joomla模板现在没有主要区域链接在Chrome中工作,但在IE中工作正常
- javascript没有'我不在Joomla 3上工作
- 如何使用Jquery添加'连字符'类到P元素在Joomla中不工作
- Joomla -引导不能正常工作
- JS FlexSlider不能在Joomla 3中工作
- Jce弹出不工作的ajax内容.在joomla
- addScript()不能在Joomla系统插件上工作
- swift容器/JavaScript只在Joomla模板的HTML主体内工作
- Joomla + jquery + prototype.不能让noConflict工作
- 如何让外部.js文件在joomla中工作
- JQuery无法工作,因为Mootools已加载到joomla中