我有这个脚本创建一个按钮...我需要创建另一个脚本来跟踪单击按钮...我将如何创建它。
<script id="navTemplate" type="text/x-jquery-template">
{{if TotalItemCount==0}}<br/>No Matches. Make sure your Marketing Info is complete.
{{else}}
<a href="#" class="rowSelectionPage" data-select="{{if AnyPageHasSelections}}false{{else}}true{{/if}}" data-selectmode="All" data-selectpageurl="PowerMatchingRowSelectionPage" >{{if AnyPageHasSelections}}un{{/if}}select entire list</a> / <a href="#" class="modalEdit" data-mode="send" data-bulkselectionmode="ServerSideRowSelections" data-method="GET" data-successmessage="Message Submitted" data-modalWidth="665" data-viewurl="/Marketing/Email/SendBuyerMatchesEmail?mode=ServerSideRowSelections&sellerId=${CaseId}" data-title="Send Email" title="Send New Email">email selected buyers</a><br />
{{/if}}
答案 0 :(得分:1)
您似乎正在使用某种框架进行绑定。如果不确切知道哪一个,我只能提供可能存在事件的内置绑定。例如,在AngularJS中有一个“ng-click”指令,它有助于将函数绑定到标准JavaScript事件。
如果没有这样的框架,那么我同意Zeaklous。您应该能够将“onClick”事件直接添加到锚标记。
<a href="#" onClick="my_tracking_function()" class="rowSelectionPage" data-select="{{if AnyPageHasSelections}}false{{else}}true{{/if}}" data-selectmode="All" data-selectpageurl="PowerMatchingRowSelectionPage" >{{if AnyPageHasSelections}}un{{/if}}select entire list</a>
<script>
function my_tracking_function() {
// Trigger some tracking event (i.e. ajax, count...)
}
</script>