为了账号安全,请及时绑定邮箱和手机立即绑定

处理jquery函数中的单引号和双引号

处理jquery函数中的单引号和双引号

PHP
忽然笑 2021-06-08 17:54:28
我从 foreach 循环创建了一个链接,因为我在 jquery 函数中显示了一个具有不同参数的链接<?php  foreach ($questions as $row) {    if (!empty($row['url_ImageName'])) {       $url_ImageName = $row['url_ImageName'];          }else{    $Paragraph =  $row['Paragraph'];    }    ?>      <a href="#" id="opendetail" onclick="question_details('<?php echo $url_ImageName; ?>','<?php echo $Paragraph; ?>')">Show Details</a>    <?php}  ?>function question_details(url_ImageName,Paragraph){  if (url_ImageName != '')   {    $(".exam-slideout .question-details img").attr("src",url_ImageName);          }  if (Paragraph != '')   {    $('.exam-slideout .question-details div').html(Paragraph);  }  }在创建这个的第一个链接中:<a href="#" id="opendetail" onclick="onclick="question_details('','“ What the deuce is it to me ” ? he interrupted impatiently: “ you say that we go round the sun. If we went round the moon it would not make a pennyworth of difference to me or to my work.”')">Show Details</a>以及创建此的第二个链接:<a href="#" id="opendetail" onclick="question_details('','Complete drying is essential before adding the sealant so that the paint doesn't smear.')">Show Details</a>在那,我遇到了单引号和双引号的问题。为了解决这个问题,我试一试$Paragraph = mysqli_real_escape_string($con, $row['Paragraph']);但功能仍然无法处理语法错误。任何人都可以帮助我。
查看完整描述

2 回答

?
ABOUTYOU

TA贡献1812条经验 获得超5个赞

只需'在字符串中间使用的之前添加一个转义字符 (\),例如:

<a href="#" id="opendetail" onclick="question_details('','Complete drying is essential before adding the sealant so that the paint doesn\'t smear.')">Show Details</a>

使用模板文字的替代方法:

<a href="#" id="opendetail" onclick="question_details('',`Complete drying is essential before adding the sealant so that the paint doesn't smear.`)">Show Details</a>

您可以了解有关在 JavaScript 中使用字符串的更多信息。


查看完整回答
反对 回复 2021-06-19
  • 2 回答
  • 0 关注
  • 238 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信