0
我需要設置一個自定義腳本來跟蹤用戶在表單提交字段上的點擊。這是我到目前爲止所做的。當用戶瀏覽表單字段時,計數器變量(基數)總計了用戶到達路徑的距離。我希望在用戶通過發送基本變量離開頁面時將結果發送出去。我正在考慮在jQuery中使用.unload函數。然而由於某種原因,卸載並沒有按照我認爲應該的方式進行響應。有任何想法嗎?使用Jquery設置表單跟蹤
var base = 0; //declares a variable of 0. This should refresh when a new user lands on the form page.
function checkPath(fieldNo, path) { //this function should check the current base value of the base variable vs the current fieldNo
if (fieldNo >= path) { //checks to see if base if lower than fieldNo
base = fieldNo; //if true, base is set to current fieldNo
return base;
} else {
return base; //if false, simply returns base.
}
};
$('#order_customer_fields_forename').focus(function() { //when the form box is selected should run checkPath then alert result.
checkPath(1, base);
});
$('#order_customer_fields_surname').focus(function() {
checkPath(2, base);
});
$('#order_customer_fields_postcode').focus(function() {
checkPath(3, base);
});
$('#order_customer_fields_address1').focus(function() {
checkPath(4, base);
});
$('#order_customer_fields_address2').focus(function() {
checkPath(5, base);
});
$(window).unload(function() {
alert(base);
});