如何将此脚本绑定到锚点's单击事件
How do I go around binding this script to an anchor's click event?
我在实现跟踪像素脚本时遇到了问题,特别是在将脚本绑定到单击事件时。
这是我从像素跟踪服务提供商那里得到的JavaScript:
<script type="text/javascript" language="javascript">
var __autoFirePixels = true;
(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.setAttribute('async', 'true');
script.src = document.location.protocol+
'//pixel.traffiliate.com/pixel/pixels.js.php'+
'allsortsofapiinformation';
document.documentElement.firstChild.appendChild(script);
})();
</script>
当点击呼叫按钮时,我需要触发这个代码——在登录页中有两个这样的按钮。
我觉得解决方案指日可待,如果能为我找到解决方案,我将不胜感激。
<a href="#" id="click-to-call">Click to call</a>
<script type="text/javascript">
var trackPixel = function() {
var __autoFirePixels = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.setAttribute('async', 'true');
script.src = document.location.protocol+
'//pixel.traffiliate.com/pixel/pixels.js.php'+
'allsortsofapiinformation';
document.documentElement.firstChild.appendChild(script);
}
document.getElementById('click-to-call').onclick = trackPixel;
document.getElementById('click-to-call2').onclick = trackPixel;
document.getElementById('click-to-call3').onclick = trackPixel;
</script>
相关文章:
- 如何使用2个事件单击1个日历
- 在 javascript 事件单击后清空输入
- 在元素 SVG 中使用 JavaScript 或 jQuery 进行事件单击
- fullCalendar动态事件单击行为
- 错误:'这'对象不正确;在JQuery中单击事件-单击时的意外行为
- 如何启用事件单击仅在指定的小时范围内
- 完整日历事件单击未触发
- 打开选择之前的事件.(单击工作速度不够快)
- 在 JavaScript 中,函数不会在事件单击时触发
- 主干分组依据集合仅在一次事件单击后呈现
- 如何禁用地图上的所有鼠标事件(单击、悬停等)
- Fullcalendar将图标添加到事件而不触发事件单击
- 在将JQuery对象添加到DOM之前,请将事件单击到JQuery对象
- 如何模拟拖动事件(单击鼠标移动按钮)
- 如果可编辑为 false,则全日历事件单击处理程序不起作用
- onclick事件单击时未添加类
- 事件单击Kml Placemark
- 事件单击时没有运行数据库
- 在事件单击函数中添加href url
- 创建元素和事件(单击)