You*_*per 3 html javascript jquery
我想在我的网页上添加以下功能:如果用户在30秒内没有按下"接受"按钮,则会$('#popupBoxAccept').click( function() {..}自动执行.
$(document).ready(function() {
loadPopupBox();
});
function loadPopupBox() { // to load the Popupbox
$('#popup_box').fadeIn("slow");
}
$('#popupBoxAccept').click( function() {
//...
});
$('#popupBoxDecline').click( function() {
//...
});
<div id="popup_box">
<a id="popupBoxAccept">Accept</a>
<a id="popupBoxDecline">Decline</a>
</div>
Run Code Online (Sandbox Code Playgroud)
var tim = setTimeout(function(){
$('#popupBoxAccept').click();
},30000);
Run Code Online (Sandbox Code Playgroud)
在手册内点击:
$('#popupBoxAccept').click(function(){
clearTimeout(tim);
// ........
});
Run Code Online (Sandbox Code Playgroud)
并且正如@Elias所建议的那样:
$('#popupBoxDecline').click( function() {
clearTimeout(tim);
//...
});
Run Code Online (Sandbox Code Playgroud)