这是我的代码:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'REMOVED']);
_gaq.push(['_setDomainName', 'REMOVED']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
var headString = "<li><a onclick='goog_report_conversion('REMOVED'); _gaq.push(['_trackEvent', 'Phone Call', 'Clicked', 'REMOVED']);' href='tel:REMOVED'>REMOVED</a> / REMOVED</li>";
jQuery('.primary-nav-menu li:first').before(headString);
jQuery(document).on('click', jQuery('#head_link'), function(e){
_gaq.push(['_trackEvent', 'Phone Call', 'Clicked', 'REMOVED']);
});
});
</script>
据客户称,“误报太多”。这也是我得到的解释:“代码中没有双引号”。但它呈现的方式可能是因为var字符串'需要正确呈现特殊字符?'
是否可以“在没有var字符串的标题中获取相同的行”?我不是JS开发人员所以我对如何实现这一点没有任何想法。
答案 0 :(得分:1)
使用\来转义双引号。
var headString = "<li><a onclick=\"goog_report_conversion('REMOVED'); _gaq.push(['_trackEvent', 'Phone Call', 'Clicked', 'REMOVED']);\" href='tel:REMOVED'>REMOVED</a> / REMOVED</li>";
答案 1 :(得分:1)
我会尝试更像:
var li = $('<li />');
var a = $('<a />', {
href:"PHONE NUMBER"
}.text("PHONE NUMBER").appendTo(li);
li.appendTo($('.primary-nav-menu li:first'));
a.on('click', function(e) {
goog_report_conversion('REMOVED');
_gaq.push(['_trackEvent', 'Phone Call', 'Clicked', 'REMOVED']);
});