簡體   English   中英

如何防止按鈕觸發aspx回發

[英]how to prevent button to trigger a postback on aspx

自從我上次使用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>

您可以阻止提交操作-

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

在您要設置彈出窗口的Jquery代碼中,最后寫入return false ...謝謝

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

在按鈕中添加type屬性, type="button" 默認是submit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM