简体   繁体   English

如何显示隐藏表格

[英]How to show hidden form

I want to show a hidden form when click on button my problem is when I click on the button the form is displayed for seconds then the page reload this is my code: 我想在单击按钮时显示一个隐藏的表单,我的问题是当我单击按钮时,该表单显示几秒钟,然后页面重新加载,这是我的代码:

Java Script: Java脚本:

function show(){
    document.getElementById("theForm").style.display="block";
}

html : html:

<button id="search" onclick="show()">show</button>
</form>
<form class="form-horizontal" action="FormController/save" method = "POST" id="theForm" style="display: none">

Default behavior of button is submit , hence the form is submitted. button默认行为是submit ,因此submitform You can use type="button" which doesn't have default behavior, thus it can be associated with client-side event handlers. 您可以使用没有默认行为的type="button" ,因此可以将其与客户端事件处理程序关联。

<button type="button" id="search" onclick="show()">show</button>

Additionally, I would recommend you do get rid of of ugly inline click handlers and bind event handler using addEventListener() 此外,我建议您不要使用丑陋的嵌入式单击处理程序,并使用addEventListener()绑定事件处理程序

 document.querySelector('#search').addEventListener("click", show, false);

HTML 的HTML

<button type="button" id="search">show</button>

If you're using jQuery as your tags says so you could do it like : 如果您使用的是jQuery,如标签所示,则可以这样进行:

$('#seach').on('click', function(){
    $('#theForm').show();
})

Hope this helps. 希望这可以帮助。

 $('#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> 

Try This: 尝试这个:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM