我想看看用戶點擊的兩個圖像是否相同。 我有一些代碼,獲取被點擊圖像的來源:如何查看兩個圖像源是否相同?
$('img').click(function() { var path = $(this).attr('src'); });
我只是需要一種方法來兩個來源相互比較。 我試圖存儲來源陣列,看如果他們是平等的,但我無法得到那個工作:
var bothPaths = [];
$('img').click(function() {
var path = $(this).attr('src');
bothPaths.push(path);
});
if (bothPaths[0] == bothPaths[1]) {
alert("they match.");
} else {
alert("they don't match.");
}
我會假設,這會比前兩個圖像源的用戶點擊,但我似乎在某個地方有問題。