我在下面的陳述中關注的陳述是fancybox = 1;如果我創建的任何臨時圖像的最大寬度超過480,則需要執行此操作。只適用於及時操作,爲什麼?
有關與此相互作用的html的一些背景信息: 我有一個包含圖像的鏈接。
圖像是一個調整大小的版本,鏈接的href是原始的,未處理的圖像。
有一系列這些鏈接包裝的圖像
div,addon-large-image,包裝整個事情。
由於某些原因,如果我有'alert(m);'這個代碼,包括在內。我正確地結束了我最後的if語句(在這種情況下,我確實有圖像寬於480),並且我得到的最後一個警告是「已觸發」。但是,如果我註釋掉'alert(m);',並且沒有其他改變,'alert(「Triggered」);'未能開火,顯示我事實上並未進入我最後的條件。
我在做什麼錯在這裏有什麼想法嗎?我在Java中有一個編程背景,但是對於Jquery而言,我從任何重要的角度來說都是新手,所以我猜測我有一種類似'alert(m);'的語法問題。有點意外的修復。
'最高'在我的問題範圍內是無關緊要的,它做到了正確的應用,在其他地方使用,並且在我實現maxWidth之前就已經存在。
var tallest = 0;
var tempImg = new Image();
var tempSrc = "";
var maxWidth = 0;
// Finds the tallest image in the set.
$("#addon-large-image img").each(function() {
var n = $(this).attr("height");
if (tallest < n) {
tallest = n;
}
tempSrc = $(this).parent().attr("href");
$(tempImg).attr("src", tempSrc);
var m = $(tempImg).attr("width");
alert(m);
if (maxWidth < m) {
maxWidth = m;
}
});
if (maxWidth > 480) {
fancybox = 1;
alert("Triggered");
}
使用火狐? – 2010-01-14 19:37:13
在Firefox和Safari中測試 – Jacob 2010-01-14 19:48:32