2011-08-26 91 views
1

我通過htmlentities($ str)迴應了引號,它首次運行,但它是在圖像上點擊時通過jQuery交換的圖像上 - 然後標題顯示html實體"

我如何可以重複使用引號的文本,以便它仍然顯示爲一個「而不是$ QUOT;?點擊後

這裏是我的html

<div class="smallImageWrapper"> 
     <?php if(empty($row_rsPTN['img1'])): echo "" ?> 
     <?php else: ?> 
     <span class="smallImage"><img src="../images/products/pbetn/50x50/<?php echo $row_rsPTN['img1']; ?>" alt="<?php echo htmlentities($row_rsPTN['img1caption']); ?>" name="smallImage" id="smallImage1" height="50px" width="50px" /></span> 
     <?php endif; ?> 

,這裏是我的jQuery來交換圖片:

$("#smallImage1").bind("click", function() { 
    $("#largeimage").attr("src","../images/products/pbetn/180x280/<?php echo $row_rsPTN['img1']; ?>"); 
    $("#largeimage").attr("alt","<?php echo htmlentities($row_rsPTN['img1caption']); ?>"); 
    $(".caption").text("<?php echo htmlentities($row_rsPTN['img1caption']); ?>"); 
}); 

這裏是我的測試網站的鏈接,你可以看到它發生: http://www.imsmfg.com/new/test/products/ptn.php?menuproduct=Lacing%20Strips

讓我知道你是否需要更多信息。 謝謝!

回答

2

改變這一行:

$("#largeimage").attr("alt","<?php echo htmlentities($row_rsPTN['img1caption']); ?>"); 

要這樣:

$("#largeimage").attr("alt","<?php echo addslashes($row_rsPTN['img1caption']); ?>"); 

jQuery將自動實體化的東西,所以你不需要把實體在該報價。你只需要轉義任何引號。因此addslashes

+0

好吧,現在我有這個錯誤:「PHP致命錯誤:調用未定義的函數addslahses()在D:\網站\ public_html \新\測試\產品\ ptn.php在線197」 – kamalo

+0

是一個錯字。固定。 (應該是「addslashes」,而不是「addslahses」)。 –

+0

[addslashes()](http://www.php.net/manual/en/function.addslashes.php) – tttony