在我的worpress中我使用短代码然后我收到了这个错误。
最初代码是这样编写的:
...
var htmlAppendString='<div class="slider_page_info"><div class="val">1</div><div class="arrow"></div></div>';
jQuery( '.wpp_pagination_slider .ui-slider-handle', this ).append(htmlAppendString);
...
当我检查页面内容的元素时,js代码变成这样。
...
var htmlAppendString='
<div class="slider_page_info">
<div class="val">1</div>
<div class="arrow"></div>
</div>
<p>';jQuery('.wpp_pagination_slider .ui-slider-handle',this).append(htmlAppendString);
...
有没有人对此有所了解? 任何帮助将不胜感激..
我试过看起来像这样的代码:
var htmlAppendString= "\<div class='slider_page_info'>\<div class='val'>1</div>\<div class='arrow'></div>\</div>";
jQuery( '.wpp_pagination_slider .ui-slider-handle', this ).append(htmlAppendString));
但是当我运行页面并检查元素时,脚本将如下所示:
....
var htmlAppendString="\
<div class='slider_page_info'>\
<div class='val'>1</div>
<p>\
<div class='arrow'></div>
<p>\</p></div>
<p>";jQuery('.wpp_pagination_slider .ui-slider-handle',this).append(htmlAppendString));
....
是否由js minify或jquery冲突引起?
答案 0 :(得分:0)
像这样更改你的代码,
...
var htmlAppendString=
'<div class="slider_page_info">'+
'<div class="val">1</div>'+
'<div class="arrow"></div>'+
'</div>'+
'<p>';
jQuery('.wpp_pagination_slider .ui-slider-handle',this).append(htmlAppendString);
...
或者您可以转义文字换行符
...
var htmlAppendString=
'<div class="slider_page_info">\
<div class="val">1</div>\
<div class="arrow"></div>\
</div>\
<p>';jQuery('.wpp_pagination_slider .ui-slider-handle',this).append(htmlAppendString);
...
如果您想使用第一种方法对齐代码,请使用\n
作为新行
...
var htmlAppendString=
'<div class="slider_page_info">\n'+
'<div class="val">1</div>\n'+
'<div class="arrow"></div>\n'+
'</div>\n'+
'<p>';
jQuery('.wpp_pagination_slider .ui-slider-handle',this).append(htmlAppendString);
...