jQuery 在 aspx 页面中无法正确显示

标签 jquery asp.net visual-studio-2010

我试图让这个函数在 aspx 页面中工作,但我过得很糟糕。基本上它在常规 HTML 页面中工作正常,但在 aspx 页面中,当单击按钮时,您只能看到顶部的一小部分,有时(每 5 个以上的单按钮单击和每次双击)消息会显示并消失就像它应该的那样。我缺少什么?它会被困在回发中吗?

FIDDLE HERE

在aspx页面中使用的代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="checkTest.aspx.cs" Inherits="WebApplication2.checkTest" %>

<!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></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#Button1").click(function () {
                    $(".message").stop(true,true).slideToggle().fadeOut(6000);
                });
            });
        </script>
    <style type="text/css">
    .message{height:70px;display:none;}
        .noChangesMessage{width:84px;padding:8px 8px;  background:#535353; -webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px; color:white;text-align:center;}
        .tipEnd{width:0;height:0;border-left:10px solid transparent;border-right:10px solid transparent;border-top:10px solid #535353;margin:0 auto;}

    </style>
</head>
<body>
    <form id="form1" runat="server">



    <br /><br /><br />
    <div>
    <div style="width:100px">
    <div style="height:70px">            
                <div style="margin-bottom:5px;" class="message">
                    <div class="noChangesMessage">No changes were made!</div>
                    <div class="tipEnd"></div>
                </div></div>
            <div style="">
                <asp:Button ID="Button1" runat="server" Text="Save Changes"  />
            </div>
            </div> 

    </div>


    </form>
</body>
</html>

我的代码通过查看 amit_g 的源代码

<!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><title>
</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#Button1").click(function () {
                    $(".message").stop(true,true).slideToggle().fadeOut(6000);
                });
            });
        </script>
    <style type="text/css">.
    .message{height:70px;display:none;}
        .noChangesMessage{width:84px;padding:8px 8px;  background:#535353; -webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px; color:white;text-align:center;}
        .tipEnd{width:0;height:0;border-left:10px solid transparent;border-right:10px solid transparent;border-top:10px solid #535353;margin:0 auto;}
    </style>
</head>
<body>
    <form method="post" action="checkTest.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA0OTM4MTAwNGRkU+SP3bu4QJNH9S9XtdwPbEE8YODY/YlkotOt6l692s8=" />
</div>
<div class="aspNetHidden">
    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKroLr3AwKM54rGBtLTfCTwYmYnb6l8tnp5jtojhvORYMJ6bPzAI+qbaDlU" />
</div>
    <br /><br /><br />
    <div>
    <div style="width:100px">
    <div style="height:70px">            
                <div style="margin-bottom:5px;" class="message">
                    <div class="noChangesMessage">No changes were made!</div>
                    <div class="tipEnd"></div>
                </div></div>
            <div style="">
                <input type="submit" name="Button1" value="Save Changes" id="Button1" class="Button1" /></div>
            </div>   
    </div>
    </form>
</body>
</html>

最佳答案

试试这个:

$("#<%= Button1.ClientID %>").click(function () {    
   $(".message").stop(true,true).slideToggle().fadeOut(6000);}
);

关于jQuery 在 aspx 页面中无法正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6207919/

相关文章:

visual-studio-2010 - 如何使用相对路径向VS项目添加图标

javascript - 如何创建简单的总价?

Jquery选择器返回html元素

asp.net - CSS Problems : Advertise over 2 divs, 布局问题

c# - 在消息框中插入图像

c++ - 如何在 C++ 中使用模板制作通用 map

c# - 如何在 ASP.NET MVC 中拥有 "service"页面?

jquery - 将 JavaScript 显示添加到主页以从 140 个字符开始倒计时。 (Rails 教程,第二版,第 10 章,练习 7)

javascript - Quasar-Framework 中 Vue 组件中的 jQuery 函数

c# - 在linq中的两列之间选择最大值