JavaScript奇淫技巧
2369 ワード
var a=[1,2,3,4,5,6,7,8];
function change(arr){
var NewArr = arr.sort(function(){Math.random()-0.5});//
return NewArr;
}
~"haha".indexOf("h");
>>-1
~"haha".indexOf("e");
>>0
~"hagha".indexOf("g");
>>-1
var a=["a","b","c","d","e"];
console.log(a[~~(Math.random()*a.length)]);
// , ~
["a","b","c","d","e"][Math.floor(Math.random()*5)]
// ,Math.floor()
var timeForm = radiobox.getElementsByTagName('input');
for (var i = 0; i < timeForm.length; i++) {
if (timeForm[i].checked) {
pageState.nowGraTime = timeForm[i].value;
}
}// OK
var timeForm = radiobox.getElementsByTagName('input');
for (var i = 0; i < timeForm.length; i++) {
if (timeForm[i].getAttribute(checked)) {
pageState.nowGraTime = timeForm[i].value;
}
}// NO
理由:getAttributeがcheckboxまたはradioのcheck値を取得するのは、各ブラウザで異なるからです.E 6/7:順次false/true IE 8に戻ります.空の文字列/checked IE 9/10/Firefox/Safari/Chrome/Opera:順次null/空の文字列に戻ります.var swip = function (turnleft) { //0 false
var r = (turnleft ? !!direction[0] : !!direction[1]) ? -1 : 1;
direction[0] += direction[1];
direction[1] = direction[0] * r - direction[1] * r;
direction[0] = direction[0] * r - direction[1];
angle += turnleft ? -90 : 90;
block.style.transform = "rotate(" + angle + "deg)";
};
var swipa = function (turnleft) {
var r;
if (turnleft) {
r = ( !!direction[0] ) ? -1 : 1;
} else {
r = ( !!direction[1]) ? -1 : 1;
}
var c;
c = direction[0];
direction[0] = direction[1] * r;
direction[1] = c * r;
angle += turnleft ? -90 : 90;
block.style.transform = "rotate(" + angle + "deg)";
};