Javascript 如何使用java脚本在单击按钮时显示特定表单

Javascript 如何使用java脚本在单击按钮时显示特定表单,javascript,forms,button,Javascript,Forms,Button,在我的jsp页面中有两个按钮,即插入和更新。单击插入按钮时,应显示插入表单,单击更新按钮时也应显示插入表单。在单击任何按钮之前,表单不应可见。我想用js实现它。这是我试过的 <button type="button" onclick="asd(1)" id="insert" value="Add new Product">insert</button> <button type="button" id="update"

在我的jsp页面中有两个按钮,即插入和更新。单击插入按钮时,应显示插入表单,单击更新按钮时也应显示插入表单。在单击任何按钮之前,表单不应可见。我想用js实现它。这是我试过的

<button type="button" onclick="asd(1)" id="insert"
            value="Add new Product">insert</button>
            <button type="button" id="update"
            value="Update Product">update</button>
    </div>  
    <script type="text/javascript">
    function asd(a)
    {
        if(a==1)
        document.getElementById("asd").style.display="none";
        else
        document.getElementById("asd").style.display="block";
    }
</script>
<form id="asd" action="">
    <h1>HII insert some data</h1>
    </form> 
插入
更新
功能asd(a)
{
如果(a==1)
document.getElementById(“asd”).style.display=“无”;
其他的
document.getElementById(“asd”).style.display=“block”;
}
HII插入一些数据

这与我的要求完全相反。我也尝试了一些其他的事情,但表单总是在我第一次加载页面时显示。我希望它是隐藏在第一,然后加载按钮点击它。提前感谢

我添加了
window.onload=function(){}
以使表单在页面加载时“不可见”。我还添加了一个
隐藏表单
按钮,使表单在单击
插入
更新
后再次消失

请参见下面的代码段:

插入
更新
隐藏形式
HII插入一些数据
window.onload=函数(){
document.getElementById(“asd”).style.display=“无”;
};
功能asd(a){
如果(a==1){
document.getElementById(“asd”).style.display=“block”;
}否则{
document.getElementById(“asd”).style.display=“无”;
}
}

在表单中添加样式:

<form id="asd" action="" style="display:none">

单击应通过除1以外的其他步骤:

<button type="button" onclick="asd(0)" ...
试试这个它会有用的
插入
更新
功能asd(a)
{
如果(a==1)
{
$('#insertf').show();
$('#updatef').hide();
}
其他的
{
$('#insertf').hide();
$('#updatef').show();
} 
}
插入表格
更新表格

您可以这样做

插入
更新
window.onload=function(){
document.getElementById('asd').style.display=“无”;
}
函数asd()
{
document.getElementById(“asd”).style.display=“block”;
}
HII插入一些数据

document.getElementById(“asd”).style.display=a?“块”:“无”
-并使用CSS隐藏它如何在第一次加载时隐藏它???
\asd{display:none}
感谢您的帮助这更优雅:
document.getElementById(“asd”).style.display=a?“块”:“无”
Try This it will work   
 <script
      src="https://code.jquery.com/jquery-3.1.1.min.js"
      integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
      crossorigin="anonymous"></script>

    <button type="button" onclick="asd(1)" id="insert" value="Add new Product">insert</button>
    <button type="button" onclick="asd(2)" id="update" value="Update Product">update</button>
        </div>  
        <script type="text/javascript">
        function asd(a)
        {
           if(a == 1)
           {
            $('#insertf').show();
            $('#updatef').hide();
           }
           else
           {
            $('#insertf').hide();
            $('#updatef').show();
           } 
        }
    </script>
     <form method="post" style="display:none !important;"  name="insert" id="insertf">
     insert form
     </form>
      <form method="post" style="display:none !important;"  name="update" id="updatef">
      update form
     </form>