脚本不会在html文件中执行

时间:2017-09-07 12:25:55

标签: javascript html node.js

我在index.html中创建了一个标头,在test.html中创建了一个单独的页面。我可以在index.html页面上使用脚本但不能在test.html页面上使用我似乎无法找到原因。

在以下文件中,控制台日志记录测试语句,我可以在浏览器中看到它。

Index.html:

<html lang="en">

<head>
    <base href="/">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Main Angular Files -->
    <script src="assets/js/angular.js"></script>
    <script src="assets/js/angular-route.js"></script>
    <script src="assets/js/angular-animate.js"></script>



    <!-- Angular Config/Routes -->
    <script src="app/app.js"></script>
    <script src="app/routes.js"></script>

    <!-- Angular Controllers -->
    <script src="app/controllers/userCtrl.js"></script>
    <script src="app/controllers/mainCtrl.js"></script>
    <script src="app/controllers/emailCtrl.js"></script>
    <script src="app/controllers/managementCtrl.js"></script>


    <script> console.log('test'); </script>    

    <!-- Angular Services -->
    <script src="app/services/userServices.js"></script>
    <script src="app/services/authServices.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>

    <!-- Cascade Style Sheets -->
    <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <link rel="stylesheet" type="text/css" href="assets/css/animate.css">




    <title>MEAN Stack App</title>

</head>

<body ng-app="userApp" ng-controller="mainCtrl as main" ng-show="main.loadme" ng-cloak>
    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-fixed-top navbar-shrink">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand page-scroll" href="/">MEAN Stack</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li class="hidden active">
                        <a href="#page-top"></a>
                    </li>
                    <li class="dropdown">
                      <a ng-show="!main.isLoggedIn" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                      <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li><a href="#">Separated link</a></li>
                        <li><a href="#">One more separated link</a></li>
                      </ul>
                    </li>
                    <li class="dropdown">
                      <a ng-show="!main.isLoggedIn" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                      <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li><a href="#">Separated link</a></li>
                        <li><a href="#">One more separated link</a></li>
                      </ul>
                    </li>
                    <li class="">
                        <a ng-show="main.isLoggedIn" class="page-scroll" href="/dashboard/{{ main.userid }}">Dashboard</a>
                    </li>
                    <li class="">
                        <a ng-show="main.isLoggedIn" class="page-scroll" href="/mytests/{{ main.userid }}">My tests</a>
                    </li>
                    <li class="">
                        <a ng-show="main.isLoggedIn" class="page-scroll" href="/comments">Comments</a>
                    </li>
                    <li class="">
                        <a ng-show="main.isLoggedIn" class="page-scroll" href="/subscriptions">Subscriptions</a>
                    </li>
                    <li class="dropdown">
                      <a ng-show="main.isLoggedIn" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                      <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li><a href="#">Separated link</a></li>
                        <li><a href="#">One more separated link</a></li>
                      </ul>
                    </li>
                    <li class="">
                        <a ng-show="main.isLoggedIn" class="page-scroll" href="/recruitafriend">Invite friend and earn MONEY</a>
                    </li>
                    <li class="dropdown">
                      <a ng-show="main.isLoggedIn" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Hello {{ main.username }} <span class="caret"></span></a>
                      <ul class="dropdown-menu">
                        <li class="">
                            <a ng-show="main.isLoggedIn" class="page-scroll" href="#" ng-click="main.logout();">Logout</a>
                        </li>
                        <li class="">
                            <a ng-show="main.isLoggedIn && main.authorized" class="page-scroll" href="/management">Management</a>
                        </li>
                        <li class="">
                            <a ng-show="main.isLoggedIn && main.authorized" class="page-scroll" href="/orders">Orders</a>
                        </li>
                        <li class="">
                            <a ng-show="main.isLoggedIn" class="page-scroll" href="/profile">Hello {{ main.username }}</a>
                        </li>
                        <li><a href="#">Separated link</a></li>
                        <li><a href="#">One more separated link</a></li>
                      </ul>
                    </li>
                    <li class="">
                        <a ng-show="!main.isLoggedIn" class="page-scroll" href="#">About</a>
                    </li>
                    <li class="">
                        <a ng-show="!main.isLoggedIn" class="page-scroll" href="#">Help</a>
                    </li>
                    <li class="">
                        <a ng-show="!main.isLoggedIn" class="page-scroll" href="/login">Login</a>
                    </li>
                    <li class="">
                        <a ng-show="!main.isLoggedIn" class="page-scroll" href="/register">Register</a>
                    </li>
                </ul>
            </div>

            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>

    <!-- Header -->
    <header ng-show="main.home">
        <div class="container">
            <div class="intro-text">
                <div class="intro-lead-in">David Acosta</div>
                <div class="intro-heading">MongoDB, ExpressJS, AngularJS, NodeJS</div>
                <a ng-show="!main.isLoggedIn" href="/login" class="page-scroll btn btn-xl">Sign In</a>
                <a ng-show="!main.isLoggedIn" href="/register" class="page-scroll btn twitterbtn">Register</a>
                <a ng-show="main.isLoggedIn" href="#" ng-click="main.logout();" class="page-scroll btn btn-xl">Logout</a>
                <a ng-show="main.isLoggedIn && main.authorized" href="/management" class="page-scroll btn facebookbtn">View</a>

            </div>
        </div>
    </header>

    <section id="services">
        <div class="container">
            <div class="row">

                <!-- Angular View -->
                <div ng-view></div>
                <!-- Angular View -->

            </div>
        </div>
    </section>

    <!-- Portfolio Grid Section -->
    <section ng-show="main.home" id="portfolio" class="bg-light-gray">
        <div class="container">
            <div class="row">
                <div class="col-lg-12 text-center">

                    <h2 class="section-heading">About This Page</h2>
                    <h3 class="section-subheading text-muted">Lorem ipsum dolor sit amet consectetur.</h3>
                </div>
            </div>
            <div class="row text-center">
                <div class="col-md-4">
                    <span class="glyphicon glyphicon-film"></span>
                    <h4 class="service-heading">YouTube</h4>
                    <p class="text-muted">Ensure you check out the YouTube video series associated with this web page. Visit:
                        <a href="https://www.youtube.com/playlist?list=PL3vQyqzqjZ637sWpKvniMCxdqZhnMJC1d" target="_blank">https://www.youtube.com/playlist?list=PL3vQyqzqjZ637sWpKvniMCxdqZhnMJC1d</a>
                    </p>
                </div>
                <div class="col-md-4">
                    <span class="glyphicon glyphicon-usd"></span>
                    <h4 class="service-heading">Facebook</h4>
                    <p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima maxime quam architecto quo inventore harum ex magni, dicta impedit.</p>
                </div>
                <div class="col-md-4">
                    <span class="glyphicon glyphicon-save"></span>
                    <h4 class="service-heading">Github</h4>
                    <p class="text-muted">Ensure you check out the GitHub page associated with this web page. Visit:
                        <a href="https://github.com/gugui3z24" target="_blank">https://github.com/gugui3z24</a>
                    </p>
                </div>
            </div>
        </div>
    </section>

    <footer ng-show="main.home">
        <div class="container">
            <div class="row">
                <div class="col-md-4">
                    <span class="copyright">Copyright © David Acosta</span>
                </div>
                <div class="col-md-4">
                    <ul class="list-inline social-buttons">
                        <li><a href="#"><i class="fa fa-twitter"></i></a>
                        </li>
                        <li><a href="#"><i class="fa fa-facebook"></i></a>
                        </li>
                        <li><a href="#"><i class="fa fa-linkedin"></i></a>
                        </li>
                    </ul>
                </div>
                <div class="col-md-4">
                    <ul class="list-inline quicklinks">
                        <li><a href="#">Privacy Policy</a>
                        </li>
                        <li><a href="#">Terms of Use</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </footer>

    <!-- BootstrapJS Modal -->
    <div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button ng-hide="main.hideButton" type="button" ng-click="main.endSession();" class="close" data-dismiss="modal">&times;</button>
                    <!-- Modal Header -->
                    <h4 class="modal-title">{{ main.modalHeader }}</h4>
                </div>
                <!-- Modal Body -->
                <div class="modal-body">
                    <p>{{ main.modalBody }}</p>
                    <div ng-show="main.hideButton" class="dizzy-gillespie"></div>
                </div>
                <div class="modal-footer">
                    <!-- Modal 'Yes' & 'No' Buttons -->
                    <button type="button" ng-hide="main.hideButton" ng-click="main.renewSession();" class="btn btn-primary" data-dismiss="modal">Yes</button>
                    <button type="button" ng-hide="main.hideButton" ng-click="main.endSession();" class="btn btn-danger" data-dismiss="modal">No</button>
                </div>
            </div>

        </div>
    </div>
    <!-- BootstrapJS Modal -->

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="assets/js/jquery-3.1.1.min.js"></script>
    <script src="assets/js/bootstrap.js"></script>
</body>

</html>

test.html不会在脚本标记中执行代码。但是h1会显示出来。

的test.html:

<div>

 <h1> Hello Test </h1> 

  <script type="text/javascript">
    console.log('2');
  </script>


</div>

1 个答案:

答案 0 :(得分:-2)

如果您不使用jquery,则Angular会使用jqlite。一旦加载了视图,就比在chrome中检查它。您不会在视图中找到script标记。因为Angular不知道如何处理脚本标记因此将其删除。当角度检测到jquery时,它将使用jquery代替jqlite进行dom操作,jqueryscript标记视为特殊标记。

< <script src="path/jquery.js"></script>   
<!-- Main Angular Files -->
<script src="assets/js/angular.js"></script>

<div>
 <h1> Hello Test </h1> 

  <script type="text/javascript">
    console.log('2');
  </script>

</div>