日期: 2012年12月5日

  • button,submit, image的区别 点onclick后隐藏行

    button,submit, image的区别 点onclick后隐藏行

    Posted on 2010-02-05 13:59 wj-conquer 阅读(142) 评论(0) 编辑 收藏  

    <input type="button" name="Submit" value="显示表单button" onclick="showAddData()"/>

    <input type="submit" name="Submit" value="显示表单submit" onclick="showAddData()"/>

    <input type="image" alt="add" src="<%=request.getContextPath() %>/images/btnImg/btn_add.gif" onclick="showAddData()" />


    如何让input type="image" onclick不提交 

            function OpenEAView(itemId) {

                if (itemId.length != 0) {

                    var pageEA = "MonthPlanItemExamineAndApprove.aspx?SessionKey=<%=this.SessionKey %>";

                    var pageUrl = pageEA + "&ItemId=" + itemId + "&action=View";

                    //var result = 

                    window.showModalDialog(pageUrl, null, features);

                    //               if (result == 'Success') {

                    //                    __doPostBack("", "");

                    //                }


                }

                 return false;//等于false 如果是提交1仍然会提交,必须加上Return

    //1 提交:  <input type="image" onclick="OpenEAView('10021921')" /> 

    //2 不提交:onclick="return OpenEAView('10021921');"

            }




    ——————————


    1.  type="button" onclick=onclick="showAddData()"      不会提交页面,只对按钮有效.


    2.  type="submit" onclick=onclick="showAddData()"      会提交页面


    3.   type="image" onclick=onclick="showAddData()"      会提交页面


    ———————————


    例:


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

    <title>关于“显示表单”与“关闭表单”的演示</title>


    <script type="text/javascript">

    function showform()

    {

    document.getElementById("lizi").style.display="block";

    }

    function closeform()

    {

    document.getElementById("lizi").style.display="none";

    }

    </script>

    </head>


    <body>

    <form id="form2" name="form2" method="post" action="">

      <table width="98%" border="1" cellspacing="0" cellpadding="0" >

        <tr>

          <td height="68"><label>

            <input type="button" name="Submit" value="显示表单" onclick="showform()"/>

            <input type="button" name="Submit2" value="关闭表单" onclick="closeform()"/>

          </label></td>

        </tr>

        <tr>

          <td height="63">wwwwww</td>

        </tr>

        <tr id="lizi" style="display: none;">

          <td height="63"><input type="text" name="test" value="aaa" /></td>

        </tr>

      </table>

    </form>

    </body>

    </html>