“预期的表达式”错误

时间:2018-07-26 11:47:07

标签: jquery laravel

我有一个页面,用户可以在其中选择注册类型,并在tinymce文本区域中输入一些内容,以将该内容与所选注册类型相关联。

但是下面的代码中显示了一个错误“期望表达”吗?

在控制台中显示错误在于这部分:

 <script type="text/javascript">

        var certificate = {};
        certificate[1] = '<p>cert1<img src="../../../img/image_1532441196_7.jpeg" alt="" width="1200" height="900" /></p>';
        certificate[2] = '<p>cert2</p>
<p>&nbsp;</p>
<p>vr</p>
<p>&nbsp;</p>
<p>ere</p>';

        $(function () {
...

完整的jQuery:

<script type="text/javascript">
        var certificate = {};
        @foreach($event->registrationTypes as $registrationType)
                @if(!$registrationType->certificate)
            certificate[{{ $registrationType->id }}] = '';
        @else
            certificate[{{ $registrationType->id }}] = '{!!   $registrationType->certificate->content !!}';
        @endif
        @endforeach

        $(function () {

            $('.radio').change(function () {

                var registrationTypeId = $('input[name=registrationType]:checked').val();
                $(tinymce.get('certificate_content').getBody()).html(certificate[registrationTypeId]);
            });

            tinymce.init({
                selector: 'textarea',
                plugins: 'image code link lists textcolor wordcount ' +
                '         hr pagebreak colorpicker textpattern anchor table media',
                relative_urls: true,

                file_browser_callback: function (field_name, url, type, win) {
                    // trigger file upload form
                    if (type == 'image') $('#formUpload input').click();
                }
            });
        });
    </script>

1 个答案:

答案 0 :(得分:2)

这应该有帮助:

@else
certificate[{{ $registrationType->id }}] = '{!!  str_replace("\r", "", str_replace("\n", "", $registrationType->certificate->content))  !!}';
@endif

因此脚本中的换行符上没有HTML字符串。