[英]Trying to track how many times java script function is called
var totalEnteredCount = 0;
function totalEntered(field){
if(field.value != '')
{
totalEnteredCount++;
}
alert(Count);
if(totalEnteredCount == 3)
{
var IV = document.getElementById("IVUnit").value;
var FV = document.getElementById("FVUnit").value;
var Distance = document.getElementById("DUnit").value;
var Acceleration = document.getElementById("AUnit").value;
var Time = document.getElementById("TUnit").value;
}
}
This function is called onBlur from HTML, every time a textbox either has data entered or not.这个函数从 HTML 调用 onBlur,每次文本框输入或不输入数据时。 If data is entered, I want it to increment the totalEnteredCount by 1. However the global variable is undefined.如果输入数据,我希望它将 totalEnteredCount 增加 1。但是全局变量未定义。 Is there a way to track how many times the function is called?有没有办法跟踪函数被调用的次数?
HTML is below: HTML如下:
<td>Initial Velocity: </td>
<td> <input type = "textbox" name ="InitVelocityInput" onKeyPress="return isAcceptable(event)" onBlur = "totalEntered(this)" id = "IVUnit"> </td>
You're trying to alert "Count" which is undefined: alert(Count);
您正在尝试提醒未定义的“计数”: alert(Count);
This cause a runtime error and prevent the rest of the code from executing.这会导致运行时错误并阻止执行其余代码。 Try to comment-out this line尝试注释掉这一行
Corrected code-更正的代码-
var totalEnteredCount = 0;
function totalEntered(field)
{
if(field.value !== '') //using !== instead of != for string comparision
{
totalEnteredCount++;
}
alert(totalEnteredCount); //using totalEnteredCount instead of Count
if(totalEnteredCount == 3)
{
var IV = document.getElementById("IVUnit").value;
var FV = document.getElementById("FVUnit").value;
var Distance = document.getElementById("DUnit").value;
var Acceleration = document.getElementById("AUnit").value;
var Time = document.getElementById("TUnit").value;
}
}
JS Bin: http://jsbin.com/xujugebeva/edit?html,js,output JS Bin: http : //jsbin.com/xujugebeva/edit?html, js, output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.