[英]keep modal from showing on page load
I have a PHP search page which querys a database. 我有一个查询数据库的PHP搜索页面。 The results are shown on the same page in a bootstrap modal.
结果以引导方式显示在同一页面上。 It works perfectly, except when the page loads, the modal shows automatically without input.
它运行完美,除了页面加载时,模式自动显示而无需输入。 If I close the modal and submit a search, it works great.
如果我关闭模式并提交搜索,则效果很好。 any suggestions?
有什么建议么?
here is the form 这是表格
<form id="myForm" method="post">
<div class="form-group">
<label class = "label-default"for="firstname">enter your first name</label>
<input type="text" name="firstname" placeholder="First Name" id="firstname" required="" oninvalid="this.setCustomValidity ('Please enter first name')" oninput= "setCustomValidity('')"/>
</div>
<label name="lastname">enter your last name</label>
<input type="text" name="lastname" placeholder="Last Name" required=""oninvalid="this.setCustomValidity ('Please enter last name')" oninput= "setCustomValidity('')" />
<button class="btn btn-primary" type="submit" value="search" >Check Seniority</button>
<button class="btn btn-outline-primary" type="reset" name="reset" id ="reset" value="reset">Reset</button>
</form>
and here is the script I am using 这是我正在使用的脚本
<script>
$(document).ready(function(){
$("#myForm").submit(function(event){
submitForm();
return false;
});
});
$(function(){
$('#myModal').modal('show');
return false;
});
;
</script>
$(function() { ... });
is shorthand of $(document).ready(function(){})
and runs on document ready state. 是
$(document).ready(function(){})
简写,并在文档就绪状态下运行。
I don't know what is submitform()
in your codes. 我不知道您的代码中的
submitform()
是什么。 If it is the function to show modal and perform a search then this is the right way to call this function: 如果它是显示模态并执行搜索的函数,则这是调用此函数的正确方法:
<script>
$(document).ready(function(){
$("#myForm").submit(function(event){
submitForm();
return false;
});
});
function submitform(){
$('#myModal').modal('show');
// and also post some data to the modal to perform search and finally:
return false;
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.