id値が ".somedivs
"で、条件文でソートされた後、コンソールにグローバル変数に格納されるシンプルなコードです。下に私はいくつかの奇妙な結果が出ていることがわかります。条件の組み合わせが何であっても、正しく動作するようにはできません。とても基本的なようですが、私はjsの法則に違反していると思っています。Javascript上位変数と下位変数条件付き奇数コンソール出力
$(document).ready(function(){
$('.somedivs').mousedown(function(){
first = $(this).attr("id");
}).mouseup(function(){
second = $(this).attr("id");
if(window.first > window.second){
var higher = window.first;
var lower = window.second;
var process = 1;
}else if(window.second > window.first){
var higher = window.second;
var lower = window.first;
var process = 2;
}else if(window.first === window.second){
var higher = window.first;
var lower = window.second;
var process = 3;
}
if(higher > lower){
var status = true;
}else{
var status = false;
}
console.log("process = " + process + " // " + "window.first = "+window.first+"/window.second = "+window.second + " // higher = "+higher+"/lower = "+lower + " // status = "+ status );
});
コンソール出力は、ほとんどの行がfalseである必要がある場合にtrueを返します。私は矢印 ">"に間違っているものの印を付けました。 ステータスが偽である必要があるのはなぜですか?
process = 2 // window.first = 0/window.second = 1 // higher = 1/lower = 0 // status = true
process = 3 // window.first = 2/window.second = 2 // higher = 2/lower = 2 // status = false
process = 1 // window.first = 2/window.second = 0 // higher = 2/lower = 0 // status = true
> process = 1 // window.first = 5/window.second = 22 // higher = 5/lower = 22 // status = true
process = 3 // window.first = 7/window.second = 7 // higher = 7/lower = 7 // status = false
process = 2 // window.first = 3/window.second = 9 // higher = 9/lower = 3 // status = true
process = 1 // window.first = 19/window.second = 14 // higher = 19/lower = 14 // status = true
> process = 1 // window.first = 5/window.second = 11 // higher = 5/lower = 11 // status = true
process = 1 // window.first = 35/window.second = 23 // higher = 35/lower = 23 // status = true
process = 2 // window.first = 13/window.second = 17 // higher = 17/lower = 13 // status = true
process = 1 // window.first = 32/window.second = 24 // higher = 32/lower = 24 // status = true
process = 2 // window.first = 17/window.second = 18 // higher = 18/lower = 17 // status = true
process = 1 // window.first = 22/window.second = 18 // higher = 22/lower = 18 // status = true
> process = 1 // window.first = 8/window.second = 11 // higher = 8/lower = 11 // status = true
process = 1 // window.first = 18/window.second = 14 // higher = 18/lower = 14 // status = true
process = 2 // window.first = 3/window.second = 6 // higher = 6/lower = 3 // status = true
process = 1 // window.first = 24/window.second = 16 // higher = 24/lower = 16 // status = true
process = 1 // window.first = 9/window.second = 15 // higher = 9/lower = 15 // status = true
process = 1 // window.first = 31/window.second = 26 // higher = 31/lower = 26 // status = true
process = 2 // window.first = 24/window.second = 28 // higher = 28/lower = 24 // status = true
process = 1 // window.first = 41/window.second = 30 // higher = 41/lower = 30 // status = true
process = 2 // window.first = 13/window.second = 19 // higher = 19/lower = 13 // status = true
私には競合状態のような匂いがします...しかし、私は –