Điều sau đây gây nhầm lẫn cho tôi rất nhiều. Như đã lưu ý trong các nhận xét, các so sánh dường như hoạt động một mình, nhưng khi đặt lại với nhau, chúng khôngNhà điều hành "==" Javascript nằm
Thời gian sẽ chạy trong cùng một tháng, sau đó tăng từng cái một, sau đó bắt đầu lại.
Tôi đã đặt toàn bộ chuỗi với console.log để cố gắng tìm ra, nhưng nó không có ý nghĩa gì cả. Mọi thứ dường như bằng nhau, nhưng vẫn thất bại trong bài kiểm tra "==" trong câu lệnh while.
var i=0;
var currentdate = 0;
var currentmonth = 0;
var opensmonth = 0;
var opens = [
{ "date":"3/30/2006","zip":"30038","latitude":"33.676358","longitude":"-84.15381"},
{ "date":"4/31/2006","zip":"30519","latitude":"34.089419","longitude":"-83.94701"}
];
intid = setInterval("stepthrough()", 250);
function stepthrough() {
//figure out first date.
if (currentdate == 0) { // we've not been run before
currentdate = opens[0]["date"];
currentmonth = currentdate.split("/", 1);
console.log("Current Month: >" + currentmonth +"<");
}
console.log("Current month: " + currentmonth + " And opensdate: " + opens[i]["date"].split("/", 1));
//
// TWILIGHT ZONE ENTERED.
//
if (currentmonth == 3) {
console.log("Current month equals 3."); // PASSES
}
if (opens[i]["date"].split("/", 1) == 3) {
console.log("Opens date equals 3."); // PASSES
}
// BOTH THE ABOVE TESTS PASS IN CHROME AND SAFARI WHAT THE F*$K JAVASCRIPT
while(opens[i]["date"].split("/", 1) == currentmonth) { // WHY DOESNT THIS WORK I HATE COMPUTERS
console.log("Trying to add a point one.");
addpoint(i);
i++;
console.log("Trying to add a point.");
}
//set the date for next iteration
currentdate = opens[i]["date"];
currentmonth = currentdate.split("/", 1);
console.log ("Current date is now: " + currentdate + " and current month is now: " + currentmonth);
jQuery('div#date').text(currentdate);
//if (i>=5000) {
if (!opens[i]["date"]) {
console.log("Clearing interval");
clearInterval(intid);
//jQuery('div#date').text("Limited at 5000 records")
}
}
thử sử dụng 'parseInt (stringValue, 10)'. –
Điều gì sẽ xảy ra nếu bạn sử dụng '===' trong dòng '// WHY DOESNT NÀY LÀM VIỆC '? [Câu trả lời này] (http://stackoverflow.com/questions/359494/javascript-vs-does-it-matter-which-equal-operator-i-use/359509#359509) gợi ý rằng '==' là tà ác và không thể tin được. – CanSpice
tôi thành thật không thấy câu hỏi ở đây. –