2011-08-26 90 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