CS_Web_Script_AutoCompleted = function(waitTime, tgtId, _onCompletedScript) {
var _timeLength = 2;
var _waitTime = 0;
var _thead;
var onCompletedScript = "alert('onCompletedScript事件未被定义');";
function ReduceWaitTime() {
if (_waitTime == 0) {
clearInterval(_thead);
/*执行脚本*/
eval(onCompletedScript);
}
else {
_waitTime--;
}
}
function BeginPress() {
clearInterval(_thead);
_waitTime = _timeLength;
_thead = setInterval(ReduceWaitTime, waitTime);
}
this.SetOnCompletedScript = function(value) {
onCompletedScript = value;
};
this.Start = function() {
BeginPress();
};
{
if (tgtId != null && tgtId != '') {
document.getElementById(tgtId).onkeyup = function() {
BeginPress();
}
}
if (onCompletedScript != null && onCompletedScript != '') {
onCompletedScript = _onCompletedScript;
}
}
};
<div>
<input id="Text1" type="text" />
<script>
new CS_Web_Script_AutoCompleted(200, 'Text1', 'alert(\'ok\');');
</script>
</div>