简体   繁体   English

不能让我的Javascript在Joomla中工作

[英]Cant get my Javascript to work in Joomla

I am having trouble getting this Javascript code to work inside my Joomla template and I cannot figure out what I am doing wrong. 我无法在我的Joomla模板中使用此Javascript代码,并且无法弄清楚自己在做什么错。 Please help. 请帮忙。

This is the script tag im trying to reference in the 'head': 这是我试图在“ head”中引用的脚本标签:

<script type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/javascript/responsive_menu.js"></script>

This is the main menu im adjusting in the 'html': 这是在“ html”中即时调整的主菜单:

<nav class="nav">
    <div data-state="closed" class="navigation">
        <a href="#" class="nav__toggle"></a>
        <img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template; ?>/images/arrow.png" alt="" class="arrow" />
        <jdoc:include type="modules" name="top" />
    </div>
</nav>

This is the 'css' im trying to affect: 这是试图影响的“ css”即时通讯:

.navigation[data-state=closed] {
    min-height: 0;
    height: 70px;
    overflow: hidden;
}

.navigation[data-state=open] {
    height: 290px;
    -webkit-transition: height ease-out 1s;
    -moz-transition: height ease-out 1s;
    -o-transition: height ease-out 1s;
    transition: height ease-out 1s;
}

And here is my Javascript inside the '.js': 这是我在'.js'中的Javascript:

(function () {

var nav = document.querySelector('.nav__toggle');
var toggleState = function (elem, one, two) {
    var elem = document.querySelector(elem);
    elem.setAttribute('data-state', elem.getAttribute('data-state') === one ? two : one);
};

nav.onclick = function (e) {
    toggleState('.navigation', 'closed', 'open');
    e.preventDefault();
};

// ES5
// nav.addEventListener('click', toggleState.bind(null, '.nav ul', 'closed', 'open'), false);

})();

I will use another solution for now but I cannot figure out why this is not working. 我现在将使用另一种解决方案,但是我无法弄清楚为什么它不起作用。

Please help. 请帮忙。

You can: 您可以:

  • Use Chrome Network/Sources to check whether the JS file is loaded 使用Chrome Network / Sources检查JS文件是否已加载
  • Use console.log to check whether the JS code is executed 使用console.log检查JS代码是否已执行
  • Use Chrome Debug to track how the JS code is run 使用Chrome调试工具跟踪JS代码的运行方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM