我需要在第一次按下按钮时显示消息.如果我再次按下按钮,它将重定向我.怎么做的JavaScript?
我有提交按钮,第一次按下按钮就会显示消息.下次按下同一个按钮时不应该显示该消息,它应该转到下一页.
请告诉我如何在javascript中执行此操作?
使用Events/one绑定一个click事件,其触发一次.在该事件处理程序中,绑定一个执行重定向的普通 click事件处理程序,从而保证消息只显示一次:
$('#myButton').one("click", function() {
alert('show me the first time only');
$(this).click(function() {
//or $('form').submit();
//or 'return true'; depending on your specific requirement
window.location.href = 'some/link.html';
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
用户第一次点击时,他会收到消息.随后的点击将转发给他some/link.html而不首先显示该消息.
| 归档时间: |
|
| 查看次数: |
285 次 |
| 最近记录: |