猿问

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

我从 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']);

但功能仍然无法处理语法错误。

任何人都可以帮助我。


忽然笑
浏览 239回答 2
2回答

ABOUTYOU

只需'在字符串中间使用的之前添加一个转义字符 (\),例如:<a&nbsp;href="#"&nbsp;id="opendetail"&nbsp;onclick="question_details('','Complete&nbsp;drying&nbsp;is&nbsp;essential&nbsp;before&nbsp;adding&nbsp;the&nbsp;sealant&nbsp;so&nbsp;that&nbsp;the&nbsp;paint&nbsp;doesn\'t&nbsp;smear.')">Show&nbsp;Details</a>使用模板文字的替代方法:<a&nbsp;href="#"&nbsp;id="opendetail"&nbsp;onclick="question_details('',`Complete&nbsp;drying&nbsp;is&nbsp;essential&nbsp;before&nbsp;adding&nbsp;the&nbsp;sealant&nbsp;so&nbsp;that&nbsp;the&nbsp;paint&nbsp;doesn't&nbsp;smear.`)">Show&nbsp;Details</a>您可以了解有关在 JavaScript 中使用字符串的更多信息。
随时随地看视频慕课网APP
我要回答