2016-12-30 59 views
0

我有一個網頁,我用Visual Basic .NET下4.0開發關閉。我有一個簡單的頁面,有一些按鈕。當我點擊一個特定的按鈕時,我執行一個使用jalert()的javascript函數。該警報顯示正確,但隨後自行關閉,無需單擊顯示的對話框上的確定按鈕。定製的jQuery警報自動

這是我的網頁代碼:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test.aspx.vb" Inherits="AccuRecordDirect.test1" %> 

<!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 id="Head1" runat="server"> 
<title id="titleTag"> 
</title>  
<meta name="viewport" content="width=device-width, initial-scale=1" /> 
<link href="~/bootstrap/content/bootstrap.css" type="text/css" rel="stylesheet" />  
<script src="~/bootstrap/Scripts/jquery-1.9.1.js" type="text/javascript"></script> 
<script src="../../bootstrap/scripts/js/jquery/jquery.js" type="text/javascript"></script> 
<script src="../../bootstrap/scripts/js/jquery/jquery.ui.draggable.js" type="text/javascript"></script> 
<script src="../../bootstrap/scripts/js/jquery/jquery.alerts.js" type="text/javascript"></script> 
<link href="../../bootstrap/scripts/js/jquery/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" /> 

<script src="~/bootstrap/Scripts/bootstrap.js" type="text/javascript"></script> 
<link href="~/Styles/Site_vsta.css" rel="stylesheet" type="text/css"/> 
<link href="~/bootstrap/content/Site_vsta.css" type="text/css" rel="stylesheet" /> 

<style type="text/css"> 
@media (min-width:992px) { 
.mobile-only {display:none;} 
} 

@media (max-width: 991px) { 
.desktop-only {display:none;} 
} 
</style> 

</head> 

<body> 
<form id="form1" runat="server"> 
    <div class="container body-content"> 
     <div class="row">    
      <div class="col-sm-7 col-sm-offset-1"> 
       <div class="panel panel-default mobile-only" style="margin-left:auto; margin-right:auto;"> 
        <div class="panel-heading""> 
         <asp:Label ID="Label7" runat="server" Text="Online Enrollment - Investment Elections" CssClass="panel-title mobile-only"></asp:Label> 
        </div> 
        <div class="panel-body"> 
         <div class="row"> 
          <div class="col-sm-10 col-sm-offset-1"> 
           <asp:Label ID="Label3" runat="server" Text="Select how you want to set up your investment elections and click the <B><I>Next</I></B> button below." CssClass="control-label mobile-only"></asp:Label> 
          </div> 
         </div> 
         <div class="row"> 
          <div class="col-sm-10 col-sm-offset-1"> 
           <asp:Label ID="Label6" runat="server" Text="&nbsp;" CssClass="control-label mobile-only"></asp:Label> 
          </div> 
         </div> 
         <div class="row"> 
          <div class="col-sm-10 col-sm-offset-1"> 
           <asp:Button ID="btnCancel_M" runat="server" Text="Cancel" CssClass="btn btn-primary btn-sm mobile-only" /> 
           <asp:Button ID="btn_Target_M" runat="server" Text="Target" CssClass="btn btn-primary btn-sm mobile-only" /> 
           <asp:Button ID="btn_Risk_M" runat="server" Text="Risk" CssClass="btn btn-primary btn-sm mobile-only" /> 
           <asp:Button ID="btn_Select_M" runat="server" Text="Select" CssClass="btn btn-primary btn-sm mobile-only" /> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</form> 

<script type="text/javascript" language="javascript"> 
    function showPopup_M() { 
     jAlert('We encourage you to take the investment risk', 'Risk Category Selected'); 
    }  
</script> 

</body> 
</html> 

這是我隱藏:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    If (Not Page.IsPostBack) Then 
     Me.btn_Risk_M.Attributes.Add("onclick", "javascript:showPopup_M();") 
    End If 
End Sub 

任何幫助是極大的讚賞。

謝謝 喬納森

回答

1

您的按鈕執行表單POST(回發)。這是正常的行爲。回發將刷新頁面,以便用JavaScript完成的任何客戶端操作都將丟失。

,如果你不使用該按鈕的任何asp.net功能的按鈕屬性更改爲

btn_Risk_M.Attributes.Add("onclick", "showPopup_M(); return false;") 

或(的OnClick,能見度等),你可以把它變成一個非ASPNET之一。

<input type="button" onclick="showPopup_M()" value="Risk" class="btn btn-primary btn-sm mobile-only" />