简体   繁体   English

父子事件监听器

[英]Parent and child event listener

I am creating a web page that uses bootstrap, jquery and inspinia template. 我正在创建一个使用引导程序,jquery和inspinia模板的网页。

I use 3 files namely index.html - Where I import all my scripts 我使用3个文件,即index.html-将所有脚本导入其中

<body ng-controller="MainCtrl" class="">

    <div id="wrapper">
        <div ng-include="'/app/components/navigation/navigation.html'"></div>
        <div ng-include="'/app/components/header and footer/headerFooter.html'"></div>
    </div>
</body>

<!-- JS -->
<script type="text/javascript" src="./assets/node_modules/jquery/dist/jquery.js"></script>
<script src="./assets/js/inspinia.js"></script>

<script type="text/javascript" src="./assets/node_modules/angular/angular.js"></script>
<script type="text/javascript" src="./assets/node_modules/bootstrap/dist/js/bootstrap.js"></script>

navigation.html - Where my side bar is in place headerFooter.html - Where the button for sidebar toggle is place navigation.html-我的侧边栏在哪里headerFooter.html-侧边栏切换的按钮在哪里

inspinia.js - where the event listener is place inspinia.js-事件侦听器所在的位置

$('.navbar-minimalize').on("click", function (event) {
    $("body").toggleClass("mini-navbar");
    SmoothlyMenu();

});

The question is, Why does whenever I press the button the side-bar doesn't turn into mini-navbar (class not applying) is this kind of setup. 问题是,为什么每当我按下按钮时,边栏都不会变成迷你导航栏(类不适用)是这种设置。

but if all the div element is in index and not using ng-include the button is toggling properly. 但是,如果所有div元素都在索引中而不使用ng-include则按钮将正确切换。

BTW: I am using bootstrap 3.xx 顺便说一句:我正在使用bootstrap 3.xx

Change: 更改:

$('.navbar-minimalize').on('click, function() {});

to: 至:

$('body').on('click', '.navbar-minimalize', function() {});

Angular insert your HTML at runtime, so your jQuery code doesn't know about your DOM on start. Angular在运行时插入您的HTML,因此您的jQuery代码一开始就不了解您的DOM。

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

相关问题 使用父级中的子事件侦听器进行反应 - React utilizing child event listener in parent 单击父项的子项时的事件侦听器 - Event listener for when child of parent is clicked 将事件侦听器添加到其父母已禁用事件的孩子 - Add event listener to child whose parent has event disabled Drop over child 会触发 parent 的“drop”事件侦听器。 我想通过特定于子的“drop”覆盖该事件侦听器 - Dropping over child triggers the “drop” event listener of parent . I want to override that event listener by a Child specific “drop” 当在Javascript中单击子元素时,如何覆盖父事件侦听器? - How to override a parent event listener when a child element is clicked in Javascript? 在AngularJS中加载子侦听器后广播父事件 - Broadcast Parent Event after Child listener loads in AngularJS 子组件发出自定义事件,但未触发父组件的侦听器 - child component emit an custom event, but parent component's listener not triggered 为多个子组件或简单的父组件添加事件监听器 - Adding event listener to multiple child components or simple parent component 子元素导致父 onmousemove 事件侦听器出现问题 - Child element is causing issues with parent onmousemove event listener 动态添加子元素的事件监听器也标记为Parent - Dynamically added child element's event listener tagged to Parent also
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM