[英]Autoclick a button to open a pop-up
I would like to automatically open a pop-up on my site after for example 5 seconds. 我想在5秒钟后自动在我的网站上打开一个弹出窗口。 So I decided to auto-click on the button which opens the pop-up.
因此,我决定自动单击打开弹出窗口的按钮。 So I tried to use : document.getElementById('button_id').click().
所以我尝试使用:document.getElementById('button_id')。click()。 However my method doesn't work.. Do you see a problem in my code?
但是我的方法不起作用。.您在我的代码中看到问题了吗?
$(document).ready(function() { setTimeout(function() { document.getElementById('button').click() }, 5000); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="row"> <button class="btn btn-info btn-lg button" type="submit" id="button" data-toggle="modal" data-target="#enquirypopup">SUBSCRIBE</button> </div>
Maybe is there an other way? 也许还有其他方法吗? With something like .show() with my pop-up?
在弹出窗口中显示.show()之类的内容吗?
Thanks. 谢谢。
Why don't you use 你为什么不使用
The html like: 的HTML像:
<div id="popup-div-id">
</div>
The CSS: CSS:
#popup-div-id
{
position:fixed;
z-index:3000;
top:50px;
left:50px;
display:none;
background-color:red;
}
And the JS: 和JS:
$(document).ready(function(){
setTimeout(function(){
$("#popup-div-id").show();
},5000)
}
So full page like: 整页像这样:
<html>
<body>
<div id="popup-div-id">
</div>
<style>
#popup-div-id
{
position:fixed;
z-index:3000;
top:50px;
left:50px;
display:none;
background-color:red;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
setTimeout(function(){
$("#popup-div-id").show();
},5000)
}
</script>
</body>
</html>
You can do like this way 你可以这样子做
$(document).ready(function(e) {
setTimeout(function() {
$('#mymodal').trigger('click');}, 5000);
});
OR for this remove data-toggle="modal" data-target="#enquirypopup"
或为此删除
data-toggle="modal" data-target="#enquirypopup"
<button class="btn btn-info btn-lg button modalpopup" data-target="enquirypopup" type="submit" id="button">SUBSCRIBE</button>
$(document).ready(function(e) {
setTimeout(function() {
$('#enquirypopup').modal("show");}, 5000);
$("body").on("click",".modalpopup" , function(){
$("#'+$(this).attr('data-target')+'").modal("show");
});
});
You should use the bootstrap's inbuilt function for triggering the modal 您应该使用引导程序的内置函数来触发模态
$(document).ready(function(){
$("#myModal").modal();
});
#myModal
is the id of the modal window. #myModal
是模态窗口的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.