Javascript 重新加载后如何显示复选框中选中的勾选项?

Javascript 重新加载后如何显示复选框中选中的勾选项?,javascript,jquery,html,angularjs,Javascript,Jquery,Html,Angularjs,我正在尝试将选中的项目保存在复选框中并显示它们。我可以在本地存储并显示它们。但是,滴答声不会被存储。每次我重新加载页面时,都会显示存储的选中项,但缺少勾号。你知道如何在选中的项目中存储勾号并在复选框中显示它们吗 我目前正在尝试的JSFIDLE代码是: html代码是 ' 您的存储未正确使用,请参考此库的官方wiki 按照入门指南,u应该通过将localstorage绑定到一个范围变量来实现它,这样它就可以为u监视和更新localstorage中的变量 就你的情况而言,应该是这样的 <di

我正在尝试将选中的项目保存在复选框中并显示它们。我可以在本地存储并显示它们。但是,滴答声不会被存储。每次我重新加载页面时,都会显示存储的选中项,但缺少勾号。你知道如何在选中的项目中存储勾号并在复选框中显示它们吗

我目前正在尝试的JSFIDLE代码是:

html代码是 '


您的存储未正确使用,请参考此库的官方wiki

按照入门指南,u应该通过将localstorage绑定到一个范围变量来实现它,这样它就可以为u监视和更新localstorage中的变量

就你的情况而言,应该是这样的

<div ng-app="myApp">
   <div ng-controller="favCtrl">


    <div ng-repeat="chip in $storage.colores" >
        <input type="checkbox" name="{{chip.codigo}}" id="{{chip.codigo}}" ng-model="chip.checked" ng-change="chipsColores()" >
        <label>{{chip.codigo}}</label>
      </div>

        <div ng-repeat="favorite in $storage.colores">
                         localStorage: {{favorite.codigo}}
                 </div>

    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/ngStorage/0.3.6/ngStorage.min.js"></script>

您的存储未正确使用,请参考此库的官方wiki

按照入门指南,u应该通过将localstorage绑定到一个范围变量来实现它,这样它就可以为u监视和更新localstorage中的变量

就你的情况而言,应该是这样的

<div ng-app="myApp">
   <div ng-controller="favCtrl">


    <div ng-repeat="chip in $storage.colores" >
        <input type="checkbox" name="{{chip.codigo}}" id="{{chip.codigo}}" ng-model="chip.checked" ng-change="chipsColores()" >
        <label>{{chip.codigo}}</label>
      </div>

        <div ng-repeat="favorite in $storage.colores">
                         localStorage: {{favorite.codigo}}
                 </div>

    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/ngStorage/0.3.6/ngStorage.min.js"></script>
<div ng-app="myApp">
   <div ng-controller="favCtrl">


    <div ng-repeat="chip in $storage.colores" >
        <input type="checkbox" name="{{chip.codigo}}" id="{{chip.codigo}}" ng-model="chip.checked" ng-change="chipsColores()" >
        <label>{{chip.codigo}}</label>
      </div>

        <div ng-repeat="favorite in $storage.colores">
                         localStorage: {{favorite.codigo}}
                 </div>

    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/ngStorage/0.3.6/ngStorage.min.js"></script>
angular.module('myApp',['ngStorage'])

  .controller('favCtrl',[ '$scope', '$filter', '$localStorage', function ( $scope, $filter, $localStorage) {

    $scope.chipsColores = function () {
        $scope.fav = $filter('filter')($scope.$storage.colores, {checked: true});
}
//move the 'colores' into storage
  $scope.$storage =  $localStorage.$default({
    colores : [
    {'nombre':'blue', 'codigo':'1111'},
    {'nombre':'green', 'codigo':'2222'},
    {'nombre':'red', 'codigo':'3333'}

  ]
});


}])