php htmlentities($str) with jQuery?


php htmlentities($str) with jQuery?

我通过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

如果你需要更多信息,请告诉我。谢谢

更改此行:

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

对此:

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

jQuery会自动对事物进行实体化,因此您不需要将实体放在该引号中。你只需要转义任何引号。因此CCD_ 2。