jquery - "expression expected" error
问题描述
I have a page where the user can select a registration type and enter some content in the tinymce textarea to associated that content to the selected registration type.
But there is shows an error "expression expected" in the code below?
In the console shows that the error is in this part:
<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> </p>
<p>vr</p>
<p> </p>
<p>ere</p>';
$(function () {
...
complete 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>
解决方案
This should help:
@else
certificate[{{ $registrationType->id }}] = '{!! str_replace("\r", "", str_replace("\n", "", $registrationType->certificate->content)) !!}';
@endif
So that there is no HTML string on a newline in your script.
推荐阅读
- amazon-web-services - 使用“for_each”创建的 Terraform 资源 - 在其他 Terraform 脚本中使用
- jquery - 如何仅使用 jQuery 使事件返回首先匹配?
- python - 将输出转换为类似日志文件的输出,直接转换为日志文件
- python - 如何使用整数 id 变量在数据库中搜索?
- java - 运算符 < 未定义参数类型 int,使用 Selenium 和 Java 创建 web 元素列表时出现维度错误
- swift - SwiftUI 将@Published viewmodel 对象值传递给@Binding
- javascript - 如何通过 @mdx-js/loader 使用新的自动反应运行时导入
- java - 我想知道如何将 JComboBox 添加到我的 JTable
- networkx - 使用networkx图算法而不构建图
- html - 如何定位html页面上的非活动元素?