-2

我在我的 php 函数中使用它,现在我在 php 中得到一个错误,我认为这是问题,( SyntaxError: missing ; 在语句第 133 行之前)我的 php 函数是:

<?php
function VISION_TO_REPORT_MESSAGES($report_tag = "test", $subject_parameters = '', $message_parameters = '', $output=true, $lang = '')
{
// action report messages templates ...
	$report_tag = strtolower(trim($report_tag));
if (strlen($report_tag))
{        

		$report_message = array();
		$db = new clsDBcms();
        $SQL = " SELECT * FROM report_messages WHERE  report_tag= " . $db->ToSQL($report_tag, ccsText) . " LIMIT 1 ";		
       $db->query($SQL);
    $Result = $db->next_record();
    if ($Result)
	{
		$report_message['lang'] = $db->f("lang");
		if(function_exists("VISION_TO_TRANSLATE"))
		{
		$report_message['subject'] = VISION_TO_MULTI_CONTENT($db->f("subject"),$lang);
		$report_message['message'] = VISION_TO_MULTI_CONTENT($db->f("message"),$lang);
		}
		else
		{
		$report_message['subject'] = $db->f("subject");
		$report_message['message'] = $db->f("message");
		}

		$report_message['css'] = $db->f("css");
		$report_message['redirect_to'] = $db->f("redirect_to");
		$report_message['type'] = $db->f("type");

			if(!empty($subject_parameters))
			{
			while (list($this_tag,$value) = each($subject_parameters))
			$report_message['subject']  = preg_replace("/".$this_tag."/i", $value, $report_message['subject']);
			}

			if(!empty($message_parameters))
			{
			while (list($this_tag,$value) = each($message_parameters))
			$report_message['message']  = preg_replace("/".$this_tag."/i", $value, $report_message['message']);
			}
		}
        $db->close();
		if($output == true && isset($report_message['message']))
		//$output = '<script type="text/javascript">';
		$output = 'toastr.options ={ 
		  "closeButton": false,
			"debug": false,
			"newestOnTop": false,
			"progressBar": true,
			"positionClass": "toast-top-center",
			"preventDuplicates": false,
			"onclick": null,
			"showDuration": "300",
			"hideDuration": "1000",
			"timeOut": "5000",
			"extendedTimeOut": "1000",
			"showEasing": "swing",
			"hideEasing": "linear",
			"showMethod": "fadeIn",
			"hideMethod": "fadeOut",
			}';
		$output .=  'toastr.' . $report_message['css'] . "('" . str_replace("'", "\\'", htmlentities($report_message['message'])) . "'" . (isset($report_message['subject']) ? ", '" . str_replace("'", "\\'", htmlentities($report_message['subject'])) . "'" : null) . ');';
        return $output;
    }		
	}
?>

我的 html 中的第 133 行是:

toastr.success('用户记录已成功更新。', '记录已更新。');

在我的页面顶部,我使用:

<link href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.2/toastr.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.js"></script>

<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.js"></script>
4

1 回答 1

0

将引导程序添加到toastr时,我没有看到任何复杂情况,但您的代码确实存在一些问题:

  1. 首先,如果您要共享代码,请尝试包含必要的库以实际运行它。您可以使用我下面的示例,或标签上的说明。
  2. toastr options = {应该有一段时间来访问对象options上的toastr属性,如下所示:toastr.options = {
  3. 同样的事情toastr-success('The...应该使用句点,而不是连字符来调用成功方法,如下所示:toastr.success('The...
  4. 如果您自动转义<strong>&lt;strong&gt;则不可能将其呈现为 html。 早就逃过了! 因此,您需要像常规 html 一样包含括号,然后告诉 toastr不要像这样转义它toastr.options.escapeHtml = false;

这是 Stack Snippets 中的一个工作演示 - 请在提出问题时将其用作未来的模板,以便人们可以看到代码中的实际问题所在。

toastr.options = {
  "closeButton": false,
  "debug": false,
  "newestOnTop": false,
  "progressBar": true,
  "positionClass": "toast-top-center",
  "preventDuplicates": false,
  "onclick": null,
  "showDuration": "300",
  "hideDuration": "1000",
  "timeOut": "5000",
  "extendedTimeOut": "1000",
  "showEasing": "swing",
  "hideEasing": "linear",
  "showMethod": "fadeIn",
  "hideMethod": "fadeOut",
  "escapeHtml": false
}

toastr.success('The <strong>User</strong> record has been successfully updated.', 'Record Updated.');
<link href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.2/toastr.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.js"></script>

<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.js"></script>

于 2015-09-25T03:05:15.013 回答