从选择列表生成随机颜色

时间:2016-01-29 22:01:44

标签: javascript drop-down-menu

当用户从选择列表中选择一个值时,我试图为结果生成随机颜色。

<script id="my-modal.html" type="text/ng-template">
  <ion-modal-view>
    <ion-header-bar>
      <h1 class="title">My Modal title</h1>
    </ion-header-bar>
    <ion-content>
      Hello!
    </ion-content>
  </ion-modal-view>
</script>

angular.module('testApp', ['ionic'])
.controller('MyController', function($scope, $ionicModal) {
  $ionicModal.fromTemplateUrl('my-modal.html', {
    scope: $scope,
    animation: 'slide-in-up'
  }).then(function(modal) {
    $scope.modal = modal;
  });
  $scope.openModal = function() {
    $scope.modal.show();
  };
  $scope.closeModal = function() {
    $scope.modal.hide();
  };
  //Cleanup the modal when we're done with it!
  $scope.$on('$destroy', function() {
    $scope.modal.remove();
  });
  // Execute action on hide modal
  $scope.$on('modal.hidden', function() {
    // Execute action
  });
  // Execute action on remove modal
  $scope.$on('modal.removed', function() {
    // Execute action
  });
});

1 个答案:

答案 0 :(得分:0)

您在return color;之前正在document.getElementById("here").innerHTML = nemo;

在这里,这应该有效:

function headline(){
  var nemo = document.getElementById("names").value;
  var letters = '0123456789ABCDEF'.split('');
  var color = '#';
  for (var i = 0; i < 6; i++ ) {
    color += letters[Math.round(Math.random() * 15)];
   }
   document.getElementById("here").innerHTML = nemo;
   return color;
}

另外,您的代码有onc lick

<button class="styled-button" type="button" onc lick="headline()">Submit</button应该是 <button class="styled-button" type="button" onclick="headline()">Submit</button

https://output.jsbin.com/zunowuvede