这是我的代码的样子:
document.addEventListener('DOMContentLoaded', function () {
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext("2d");
var imageData = ctx.getImageData(0, 0, 300, 300);
var tile = {
'id': 1,
'data': imageData,
'dataUrl': imageData.toDataUrl()
};
var div = document.createElement('div');
div.classList.add('tile');
grid.appendChild(div);
div.style.backgroundImage = ('url(' + tile.dataUrl + ')');
});
Run Code Online (Sandbox Code Playgroud)
我正在尝试从(0,0)高度和宽度为300px的画布上提取图像的一部分,并将该imageData对象转换为dataUrl以用作div的背景.
我收到一个错误:imageData.toDataUrl()不是一个函数.我怎样才能做到这一点?
提前致谢!
我有一个看起来像这样的结构:http://jsfiddle.net/deeptechtons/TKVH6/
<div>
<ul ng-controller="checkboxController">
<li>Check All
<input type="checkbox" ng-model="selectedAll" ng-click="checkAll()" />
</li>
<li ng-repeat="item in Items">
<label>{{item.Name}}
<input type="checkbox" ng-model="item.Selected" />
</label>
</li>
</ul>
</div>
angular.module("CheckAllModule", [])
.controller("checkboxController", function checkboxController($scope) {
$scope.Items = [{
Name: "Item one"
}, {
Name: "Item two"
}, {
Name: "Item three"
}];
$scope.checkAll = function () {
if ($scope.selectedAll) {
$scope.selectedAll = true;
} else {
$scope.selectedAll = false;
}
angular.forEach($scope.Items, function (item) {
item.Selected = $scope.selectedAll;
});
};
});
Run Code Online (Sandbox Code Playgroud)
选中或取消选中全部选中后,将选中所有其他复选框.但是当选择"全部检查"并取消选择其中一个项目时,我希望取消选中"全部检查". …