2012-12-11 45 views
0

我想在JavaScript中製作圖像鏈接而不是文本鏈接。我對JavaScript很陌生,我只是無法弄清楚爲什麼我所做的不工作!它可以在HTML中工作。JavaScript中的圖像鏈接

此作品(文字鏈接 '關閉[x]'):

closeLinkString = "<div class='close'><a href='#' id='close-link' onclick=\"Megadropdowns.closeDropDown(); return false;\">close [x]</a></div>", // this is the close button 

但出於某種原因,這並不:

closeLinkString = "<div class='close'><a href='#' id='close-link' onclick=\"Megadropdowns.closeDropDown(); return false;\"><img src="/images/loading.gif"></a></div>", // this is the close button 

誰能幫我這個?

回答

7

你可以從SO的語法高亮看到的,你需要使用\",而不是逃避圖像標籤"

closeLinkString = "<div class='close'><a href='#' id='close-link' onclick=\"Megadropdowns.closeDropDown(); return false;\"><img src=\"/images/loading.gif\"></a></div>" 
3

基本的顏色編碼任何編輯器,甚至您的文章在這個網站上會立即告訴你,你沒有逃過圖像中的引號。