All*_*son 6 javascript validation function onclick delay
HTML是:
<input name="submit"
type="submit"
class="button"
value="Click Here"
tabindex="13"
onclick="return ValidateForm();" />
Run Code Online (Sandbox Code Playgroud)
ValidateForm()函数具有所有常用的表单验证代码.我无法运行的另一个功能(除了它本身它工作正常..例如
<input name="submit"
type="submit"
class="button"
value="Click Here"
tabindex="13"
onclick="disDelay(this);" />
Run Code Online (Sandbox Code Playgroud)
我试过把它们放在onclick ...例子之后
<input name="submit"
type="submit"
class="button"
value="Click Here"
tabindex="13"
onclick="return ValidateForm(); disDelay(this);" />
Run Code Online (Sandbox Code Playgroud)
我也尝试将一个代码放在同一个函数中但没有成功.
函数disDelay()是
function disDelay(obj){
obj.setAttribute('disabled','disabled');
setTimeout(function(){obj.removeAttribute('disabled')},10000);
}
Run Code Online (Sandbox Code Playgroud)
它将被用作延迟,以防止表单从多次点击中获得重复提交.现在延迟是10秒,仅用于测试目的.我需要验证和延迟一起工作.
返回第一个函数的值将终止单击处理程序。本质上,这就是您在尝试组合时所做的事情:
<input name="submit" type="submit" class="button"
value="Click Here" tabindex="13"
onclick="return submit_Click(this);" />
<script type="text/javascript">
function submit_Click(sender) {
return ValidateForm();
disDelay(sender); // !!! This call is unreachable !!!
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是纠正它的一个简单选项:
<input name="submit" type="submit" class="button"
value="Click Here" tabindex="13"
onclick="return submit_Click(this);" />
<script type="text/javascript">
function submit_Click(sender) {
var r = ValidateForm();
disDelay(sender); // It seems like you would only want to call this
// function if the form is validate, so there should
// probably be an if-statement surrounding it. However,
// I'll leave that up to you.
return r;
}
</script>
Run Code Online (Sandbox Code Playgroud)