[英]How to show hidden form
我想在单击按钮时显示一个隐藏的表单,我的问题是当我单击按钮时,该表单显示几秒钟,然后页面重新加载,这是我的代码:
Java脚本:
function show(){
document.getElementById("theForm").style.display="block";
}
html:
<button id="search" onclick="show()">show</button>
</form>
<form class="form-horizontal" action="FormController/save" method = "POST" id="theForm" style="display: none">
button
默认行为是submit
,因此submit
了form
。 您可以使用没有默认行为的type="button"
,因此可以将其与客户端事件处理程序关联。
<button type="button" id="search" onclick="show()">show</button>
此外,我建议您不要使用丑陋的嵌入式单击处理程序,并使用addEventListener()
绑定事件处理程序
document.querySelector('#search').addEventListener("click", show, false);
的HTML
<button type="button" id="search">show</button>
如果您使用的是jQuery,如标签所示,则可以这样进行:
$('#seach').on('click', function(){
$('#theForm').show();
})
希望这可以帮助。
$('#search').on('click', function(){ $('#theForm').show(); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="search">Show</button> <br> <form class="form-horizontal" action="FormController/save" method = "POST" id="theForm" style="display: none"> MY FORM </form>
尝试这个:
Java Script:
function show(){
document.getElementById("theForm").style.display="block";
}
html :
<input type="button" onclick="show()" id="search" value="show">
</form>
<form class="form-horizontal" action="FormController/save" method = "POST" id="theForm" style="display: none">
<script>
$(document).ready(function(){
$("#what").click(function() { //call event
$(".hello").hide();//hide forms
$('neededFormOnly').show(); //show only the needed form
return false
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.