【问题标题】:html bold tag ignored by browser using phphtml粗体标签被浏览器使用php忽略
【发布时间】:2015-02-21 09:46:36
【问题描述】:

我有一个将数据输入到 sql 表中的 ajax 脚本,并且在提交时我提供了一个带有消息的模式,其中显示了我在用 php 中的粗体标记回显 $name 变量时遇到问题的人的姓名

这是我在我的 php 文件中使用 echo 语句的方式

echo "Thank you <b>'$name'</b> for submitting your details. This has now   been saved in our registry.";

然后我使用以下内容在模态对话框中设置 p 标签的文本

$.ajax({
        type: 'POST',
        url: $(form).attr('action'),
        data: formData
        }).done(function(response) {
           $(formMessages).text(response);
          showModal();
});

当模式显示时,我收到“感谢&lt;b&gt;Mike Stevens&lt;/b&gt; 提交您的详细信息......”

浏览器似乎忽略了&lt;b&gt; 标签,或者我在 echo 语句中遗漏了一些东西

感谢您的帮助

【问题讨论】:

    标签: php jquery html string echo


    【解决方案1】:

    您需要使用 .html() 将 html 内容设置为 $(formMessages)。如果您使用 .text,它将自动为您转义,并且 html 显示为纯文本。

    将您的 javascript 更改为:

    $.ajax({
        type: 'POST',
        url: $(form).attr('action'),
        data: formData
        }).done(function(response) {
           $(formMessages).html(response);
          showModal();
    });
    

    【讨论】:

      猜你喜欢
      • 2012-04-02
      • 2018-09-10
      • 2010-12-29
      • 2022-01-14
      • 2023-02-10
      • 2011-05-08
      • 2011-10-24
      • 2014-12-08
      • 1970-01-01
      相关资源
      最近更新 更多