Skip to main content
 首页 » 编程设计

c#之jQuery 和 ASP.NET 页面加载

2024年02月20日12daizhj

我使用 Webcontrols 测试 jQuery 和 ASP.NET,在我的测试中,如果我点击按钮,每次都会加载 Side。 jQuery 代码将 Css 类添加到标签。

我的aspx:

      <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="jQueryAnwendung.Main" %> 
 
<!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 runat="server"> 
    <title>jQuery Anwendung</title> 
 
    <script src="Scripte/jquery-1.8.0.min.js" type="text/javascript"></script> 
 
    <style type="text/css"> 
        .CssKlasse  
        { 
            background:red; 
            font-size:40px;  
            } 
    </style> 
 
    <script type="text/javascript" language="javascript"> 
 
        $(document).ready(function () { 
            $("#<%= b1.ClientID%>").click(function (event) { 
                $("#<%= bild1.ClientID %>").slideToggle('slow'); 
            }); 
 
        }); 
 
    </script> 
 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
        <asp:Button ID="b1" runat="server" text="Bild verkleinern/vergrößern"/> 
        <asp:Image ID="bild1" runat="server" ImageUrl="~/Theme/net.png" Width="50" Height="50" />  
    </div> 
    </form> 
</body> 
</html> 

我能做什么?

塔拉索夫

请您参考如下方法:

在您的处理程序中,防止按钮正常运行:

$("#<%= b1.ClientID%>").click(function (event) { 
  event.preventDefault(); //prevent the control to act in its default way 
  $("#<%= bild1.ClientID %>").slideToggle('slow'); 
});