我正在为一个客户端工作,一个机构已经建立了一小部分jQuery来启动DoubleClick Floodlight代码,但由于某些原因,该代码无效:
<script type="text/javascript"> $(function () { //var origOnClick = $('#trackingButton').attr("onclick"); $('#trackingButton').click(fireFloodlight); function fireFloodlight() { if (Page_IsValid) { var axel = Math.random() + ""; var a = axel * 10000000000000; $("body").append('<img src="https://ad.doubleclick.net/activity;src=2499215;type=axa_l124;cat=lpg_g263;ord=' + a + '?" width="1" height="1" alt=""/>'); //eval(origOnClick); } } }); </script>
对我来说这个脚本看起来不错,但在现场环境中,对“ad.doubleclick.net”的调用从来没有任何帮助将不胜感激.奇怪的是,这个标签正在工作,直到这个周末,但现在没有记录任何行动?
编辑:我做了一个console.log(Page_IsValid),它返回True.
编辑:这是有关按钮的HTML:
<input type="submit" name="ctl00$ctl00$ctl00$BodyPlaceHolder$BodyPlaceHolder$WizardContentPlaceHolder$WizardCollectBasicSMEInfo$trackingButton" value="Get your quick quote" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$ctl00$BodyPlaceHolder$BodyPlaceHolder$WizardContentPlaceHolder$WizardCollectBasicSMEInfo$trackingButton","",true,"Form",false,false))" id="trackingButton" class="button" />
解决方法
您已经有文档准备好的功能,你的问题是你以错误的方式调用函数,如果你想调用这样的函数,你应该将其声明为一个函数表达式(
see Function Expressions in this link for more info):
$(function () { var fireFloodlight = function() { if (true) { var axel = Math.random() + ""; var a = axel * 10000000000000; $("body").append('<img src="http://tejedoresdesuenos.com.mx/wp-content/uploads/2011/06/google.jpg" width="50" height="10" alt=""/>'); alert('ello'); } } $('#trackingButton').click(fireFloodlight); });
一个工作example.