我有以下脚本,我必须有条件地添加到页面中:
<!-- Google Code for Greenwich UC Page Visits Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 659;
var google_conversion_language = "en";
var google_conversion_format = "1";
var google_conversion_color = "ffffff";
var google_conversion_label = "u8098adasxma";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/659/?label=i70ZCKnX-WAQ39343AM&guid=ON&script=0"/>
</div>
</noscript>
因此,如果Url的参数为456,请将上述脚本添加到页面中。我尝试了以下但不起作用:
var vSpecID = getParameterByName('id');
var vCode = "<!-- Google Code for Greenwich UC Page Visits Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 659;
var google_conversion_language = "en";
var google_conversion_format = "1";
var google_conversion_color = "ffffff";
var google_conversion_label = "u8098adasxma";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/659/?label=i70ZCKnX-WAQ39343AM&guid=ON&script=0"/>
</div>
</noscript>";
if (vSpecID == "456") {
$(".fg").html();
}
<div id="fg" class="fg">
</div>
由于变量中的多行,问题正在发生。请帮我解决。
答案 0 :(得分:1)
尝试使用+
和'
而不是"
来连接这些行,因为变量中的代码中有另一个双引号,这会导致问题:
var vCode = '<!-- Google Code for Greenwich UC Page Visits Conversion Page -->'+
'<script type="text/javascript">'+
'/* <![CDATA[ */'+
'var google_conversion_id = 659;'+
'var google_conversion_language = "en";'+
'var google_conversion_format = "1";'+
.....
希望这有帮助。