10/04/15 11:17:47
>>657
<html><head></head><body>
<form><input type="button" value="すべて選択" onclick="sel(1);" /><input type="button" value="すべて解除" onclick="sel(0);" /><div id="imgCheck"></div></form>
<script type="text/javascript">
Number.prototype.zero = function(n) { return ('0000000000' + this).slice(-n); };
var addEvent = function(node, type, fn) {
if (document.addEventListener) node.addEventListener(type, fn, false);
else if (document.attachEvent) node.attachEvent('on' + type, function(e) { fn.call(node, e); });
}, sel = function(num) {
var nodes = document.getElementById('imgCheck').getElementsByTagName('input');
for (var i = 0; nodes[i]; i++) (function(node) {
if (num == 0) node.checked = false;
else node.checked = true;
})(nodes[i]);
}, html = '';
for (var i = 0; i < 10; i++) {
var src = 'img' + i.zero(4) + 'jpg';
html += '<div class="imgbox"><img src="' + src + '.jpg" alt="' + src + '" /><div><input type="checkbox" value="' + src + '">' + src +'</div></div>';
}
document.getElementById('imgCheck').innerHTML = html;
addEvent(document.getElementById('imgCheck'), 'mouseover', function(e) {
var t = e.target || e.srcElement;
if (t.nodeName == 'INPUT' && t.type =='checkbox') t.checked = !t.checked;
});
</script>
</body></html>