首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >你把特定页面的脚本放哪了?

你把特定页面的脚本放哪了?
EN

Stack Overflow用户
提问于 2015-03-22 22:13:22
回答 1查看 1.1K关注 0票数 0

我正在制作一个与离子应用程序,我有JS脚本为每一页。例如,一个页面有一个将根据一天中的时间更改消息的脚本,而另一个页面有一个jQuery .load()脚本。两者似乎都不起作用。它们是DOM操作的,并且位于页面底部。

代码语言:javascript
运行
复制
<ion-view view-title="Welcome" style="text-align:center; padding:20px;">
  <ion-content>
    <h1 id="time">Hello!</h1>
      <p>Welcome to the app. We are thrilled to share our new app with you!</p>
  </ion-content>
   <script>
       date = new Date();
       var hours = date.getHours();
       console.log(hours);
       if (hours >= 5 && hours <= 11) //MESSAGE FOR MORNING
document.getElementById('time').innerHTML = 'Good Morning.';
else if (hours >= 12 && hours <= 17) //MESSAGE FOR AFTERNOON
document.getElementById('time').innerHTML = 'Good Afternoon.';
else if (hours >= 18 && hours <= 20) //MESSAGE FOR EVENING (6pm-8pm)
document.getElementById('time').innerHTML = 'Good Evening.';
else //MESSAGE FOR NIGHT (9pm-4am)
document.getElementById('time').innerHTML = 'Good Night.';</script> 
</ion-view>

Controllers.js:

代码语言:javascript
运行
复制
angular.module('starter.controllers', [])

.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
  // Form data for the login modal
  $scope.loginData = {};

  // Create the login modal that we will use later
  $ionicModal.fromTemplateUrl('templates/login.html', {
    scope: $scope
  }).then(function(modal) {
    $scope.modal = modal;
  });

  // Triggered in the login modal to close it
  $scope.closeLogin = function() {
    $scope.modal.hide();
  };

  // Open the login modal
  $scope.login = function() {
    $scope.modal.show();
  };

  // Perform the login action when the user submits the login form
  $scope.doLogin = function() {
    console.log('Doing login', $scope.loginData);

    // Simulate a login delay. Remove this and replace with your login
    // code if using a login system
    $timeout(function() {
      $scope.closeLogin();
    }, 1000);
  };
})

.controller('PlaylistsCtrl', function($scope) {
  $scope.playlists = [
    { title: 'Reggae', id: 1 },
    { title: 'Chill', id: 2 },
    { title: 'Dubstep', id: 3 },
    { title: 'Indie', id: 4 },
    { title: 'Rap', id: 5 },
    { title: 'Cowbell', id: 6 }
  ];
})

.controller('PlaylistCtrl', function($scope, $stateParams) {
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-24 01:21:36

您将脚本放在controller.js文件中。添加以下代码:

代码语言:javascript
运行
复制
.controller('PageCtrl', function($scope){
//Insert function code here
})

在离子页面上,在<ion-view>参数中,将"ng-controller"设置为PageCtrl。在DOM操作的div中,放置类似于<div>{{hello}}</div>的内容。然后,通过在控制器内使用$scope.hello = "Your String";操作DOM元素来完成所有操作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29200475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档