如何防止按钮在aspx上触发回发

时间:2014-01-21 15:01:37

标签: c# jquery asp.net jquery-ui popup

自从我上次使用JQUERY-UI制作网站以来已经有一段时间了。我有一个aspx页面,我试图在点击

时添加一个弹出模式

但是当我点击按钮时会触发“提交”,如何阻止提交?它会显示弹出窗口2秒钟,然后“提交”。

这是html代码

    <div id="dialog-form" title="Create new user">
      <p class="validateTips">All form fields are required.</p>

      <form>
      <fieldset>
        <label for="name">Name</label>
        <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all">
        <label for="email">Email</label>
        <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all">
        <label for="password">Password</label>
        <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all">
      </fieldset>
      </form>
    </div>


    <div id="users-contain" class="ui-widget">
      <h1>Existing Users:</h1>
      <table id="users" class="ui-widget ui-widget-content">
        <thead>
          <tr class="ui-widget-header ">
            <th>Name</th>
            <th>Email</th>
            <th>Password</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>John Doe</td>
            <td>john.doe@example.com</td>
            <td>johndoe1</td>
          </tr>
        </tbody>
      </table>
    </div>
    <button id="create-user">Create new user</button>

4 个答案:

答案 0 :(得分:4)

您可以阻止提交操作 -

$('form').on('submit',function(e){
   e.preventDefault();
});

答案 1 :(得分:0)

在你设置弹出写入的Jquery代码中 最后还是假...谢谢

答案 2 :(得分:0)

最简单的方法是返回false OnClientClick,<asp:Button OnClientClick="return false;"></button>

答案 3 :(得分:0)

在按钮type="button"中添加type属性。默认情况下为submit