2012-12-28 24 views
-1

你好,我是jquery的新手。在Jquery中使用圖像無法正常工作 - 轉義引號

我在WordPress的

一個投票系統,這是代碼

工作正常位時

$.post('<?php echo admin_url('admin-ajax.php'); ?>', data, 
    function(response){ 
     if(response!="-1") { 
      el.html("VOTED").unbind("click"); 
      if(response=="null") { 
       alert("A vote has already been registered to this IP address."); 
      } else { 
       $("#votecounter").html(response); 
       alert("Thanks for your vote."); 
      } 

el.html("VOTED") 

使用文本,但在我使用 這個我使用這個不起作用

el.html("<img width="584" height="455" src="/wp-content/uploads/2012/12/Hydrangeas.jpg" class="attachment-large wp-post-image" alt="Hydrangeas">") 
+3

我不會就如何繞過投票系統的用戶信息。不要說「這個IP已經投票」,只需寫下「你已經投了票」。 – eandersson

+0

多色字符串突出顯示錶示某件事不正確。在SO中發佈問題之前,請檢查JSLint的語法,控制檯錯誤,文檔等。 – elclanrs

回答

2

嘗試:

el.html('<img width="584" height="455" src="/wp-content/uploads/2012/12/Hydrangeas.jpg" class="attachment-large wp-post-image" alt="Hydrangeas">') 
+1

This Worked –

+0

如何添加類別 之後 el.html() add.class –

3

您需要轉義引號。 Stack Overflow中的語法高亮顯示器甚至顯示帖子的格式不正確。

例子:

el.html("<img width=\"584\" height=\"455\" src=\"/wp-content/uploads/2012/12/Hydrangeas.jpg\" class=\"attachment-large wp-post-image\" alt=\"Hydrangeas\">")