Javascript 不是';不在那里吗?
我犯了一个基本上不存在的错误,或者我是个超级盲人,因为我在这上面花了30分钟Javascript 不是';不在那里吗?,javascript,css,smarty,Javascript,Css,Smarty,我犯了一个基本上不存在的错误,或者我是个超级盲人,因为我在这上面花了30分钟 <b>Fatal error</b>: Uncaught --> Smarty Compiler: Syntax error in template "file:C:\htdocs\smarty\templates\shopify_apps\bundle\js_modules\product_reviews.tpl" on line 30
<b>Fatal error</b>: Uncaught --> Smarty Compiler: Syntax error in template "file:C:\htdocs\smarty\templates\shopify_apps\bundle\js_modules\product_reviews.tpl" on line 30 "$('head').append('<style> .ratings {position: relative !important;vertical-align: middle!important;display: inline-block!important;color: #b1b1b1!important; overflow: hidden!important;}.full-stars {position: absolute;left: 0;top: 0; white-space: nowrap;overflow: hidden; color: #fde16d;} .empty-stars:before, .full-stars:before {content:"\2605\2605\2605\2605\2605"; font-size: 14pt;}.empty-stars:before {-webkit-text-stroke: 1px #848484;}.full-stars:before {-webkit-text-stroke: 1px orange;} @-moz-document url-prefix() {.full-stars {color: #ECBE24;}}</style>');" - Unexpected ": ", expected one of: "}" <--
thrown in <b>C:\htdocs\vendor\smarty\smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php</b> on line <b>30</b><br />
致命错误:未捕获--Smarty编译器:模板“文件中的语法错误:C:\htdocs\Smarty\templates\shopfify\u apps\bundle\js\u modules\product\u reviews.tpl”第30行“$('head')。append('style.ratings'){位置:相对!重要;垂直对齐:中间!重要;显示:内联块!重要;颜色:#b1b1b1!重要;溢出:隐藏!重要;}.满星{位置:绝对;左:0;顶部:0;空白:nowrap;溢出:隐藏;颜色:#fde16d;}.空星:之前,.满星:之前{内容:“\2605\2605\2605\2605\2605\2605”;字体大小:14pt;}.empty stars:before{-webkit text stroke:1px#848484;}.full stars:before{-webkit text stroke:1px orange;}@-moz文档url-prefix(){.full stars{color:#ECBE24;}/style');“-意外”:”,应为:“}--
在第30行的C:\htdocs\vendor\smarty\smarty\libs\sysplugins\smarty\u internal\u templatecompilerbase.php中抛出
这就是导致它的原因
if ($('h1').length) {
$('h1').after('<span>' + message[1] + '<div class="ratings"><div class="empty-stars"><div class="full-stars" style="width=(avgStars*20)%"></div></div></div></span>');
$('head').append('<style> .ratings {position: relative !important;vertical-align: middle!important;display: inline-block!important;color: #b1b1b1!important; overflow: hidden!important;}.full-stars {position: absolute;left: 0;top: 0; white-space: nowrap;overflow: hidden; color: #fde16d;} .empty-stars:before, .full-stars:before {content:"\2605\2605\2605\2605\2605"; font-size: 14pt;}.empty-stars:before {-webkit-text-stroke: 1px #848484;}.full-stars:before {-webkit-text-stroke: 1px orange;} @-moz-document url-prefix() {.full-stars {color: #ECBE24;}}</style>');
}
if($('h1').length){
$('h1')。在(''+消息[1]+'')之后;
$('head').append('.ratings{position:relative!important;vertical align:middle!important;display:inline block!important;color:#b1b1b1b1b1b1!important;overflow:hidden!important;}.full stars{position:absolute;left:0;top:0;white space:nowrap;overflow:hidden;color:#:fde16d;}“\2605\2605\2605\2605\2605”;字体大小:14pt;}。空星:在{-webkit文本笔划:1px#848484;}之前。全星:在{-webkit文本笔划:1px橙色;}之前@-moz文档url-前缀(){;
}
任何人有什么想法吗?如果JS代码在Smarty模板文件中,您必须将其包装在标记中。您的代码应该是:
{literal}
if ($('h1').length) {
$('h1').after('<span>' + message[1] + '<div class="ratings"><div class="empty-stars"><div class="full-stars" style="width=(avgStars*20)%"></div></div></div></span>');
$('head').append('<style> .ratings {position: relative !important;vertical-align: middle!important;display: inline-block!important;color: #b1b1b1!important; overflow: hidden!important;}.full-stars {position: absolute;left: 0;top: 0; white-space: nowrap;overflow: hidden; color: #fde16d;} .empty-stars:before, .full-stars:before {content:"\2605\2605\2605\2605\2605"; font-size: 14pt;}.empty-stars:before {-webkit-text-stroke: 1px #848484;}.full-stars:before {-webkit-text-stroke: 1px orange;} @-moz-document url-prefix() {.full-stars {color: #ECBE24;}}</style>');
}
{/literal}
{literal}
如果($('h1')。长度){
$('h1')。在(''+消息[1]+'')之后;
$('head').append('.ratings{position:relative!important;vertical align:middle!important;display:inline block!important;color:#b1b1b1b1b1b1!important;overflow:hidden!important;}.full stars{position:absolute;left:0;top:0;white space:nowrap;overflow:hidden;color:#:#fde16d;}\2605\2605\2605\2605\2605;字体大小:14pt;}。空星:在{webkit text stroke:1px#848484;}之前。全星:在{webkit text stroke:1px orange;}@-moz文档url-prefix(){.full stars{color:#ECBE24;})之前;
}
{/literal}
它应该可以工作。如果不行,请将Smarty模板文件的完整代码放入您的问题中,我可能会帮助您。我猜您的编译器不喜欢在JS部分看到HTML,即使它是字符串。JS实际上是有效的。请检查您的HTML以查找在脚本之前未关闭的标记。链接到文档: