2011-04-28 130 views
2


我試圖在單擊圖像時提醒某些文本。.click()對圖像無法正常工作

javascript代碼:

$(document).ready(function() { 
    $(".delRow").click('function() { 
     alert("hello!"); 
    }); 
}); 

的html代碼:

<img src="../images/delete.png" alt="delete" class="delRow"></img> 

此代碼似乎直截了當;但是,它沒有按預期工作。使用.click時圖像的處理方式是否有所不同?

-Thanks,
豐富

+1

那是''''之前函數(){'的問題,一個錯字或者是在你的代碼? – icktoofay 2011-04-28 02:56:16

+1

它在做什麼/不做什麼?我注意到''.click('function()...'中有一個打開的引號,這是你的文章中的錯字,還是在你的代碼中? – 2011-04-28 02:58:17

+0

這是一個錯字,我將代碼改爲: \t $( 「delRow。 」)點擊(函數(){ \t警報(「 你好!」); \t}); 但是,它仍然無法按預期工作,我與他們班多張圖片。但我不認爲這會導致問題 – dottedquad 2011-04-28 03:08:10

回答

3
$(document).ready(function() { 
    $(".delRow").click(function() { 
     alert("hello!"); 
    }); 
}); 

WORKING DEMO

+0

該代碼按照預期的方式工作。我的形象仍然存在問題。 – dottedquad 2011-04-28 03:12:44

+0

在導致此問題的.click之前有代碼:-) – dottedquad 2011-04-28 03:37:03

+0

很高興您找到答案@dottedquad請將您的解決方案發布並接受爲答案或接受此處給出的答案之一 – mcgrailm 2011-04-28 14:37:25

2

你有多餘'的點擊。(函數(){

應該

$(document).ready(function() { 
    $(".delRow").click(function() { 
     alert("hello!"); 
    }); 
}); 
+0

Arg!我總是這樣做! – dottedquad 2011-04-28 03:04:38

1
$(document).ready(function() { 
    $(".delRow").click(function() { 
     alert("hello!"); 
    }); 
}); 

刪除 「'」 前秒function