开发者

php htmlentities($str) with jQuery?

I'm echoing quotes through htmlentities($str) and it works the first time, but it's for caption's on images that are being swapped via jQuery when clicked- then the caption shows the html entity ".

How can I echo the text with quotes so that it still appears as a " instead of the $quot; after clicked?

Here's my html

<div class="smallImageWrapper">
      <开发者_C百科;?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; ?>

and here's my jQuery to swap the images:

$("#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']); ?>");
});

here's a link to my test site where you can see it occurring: http://www.imsmfg.com/new/test/products/ptn.php?menuproduct=Lacing%20Strips

Let me know if you need more info. Thanks!


Change this line:

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

To this:

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

jQuery entitizes things automatically, so you don't need to put entities in that quote. You just need to escape any quotes. Hence addslashes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜