2011-06-29 58 views
0

我做了一个小的风格改变应用程序在Asp.Net 3.5中使用jquery。我有IE7。 当我点击按钮的段落颜色应该改变。 问题是,颜色在变化,它不稳定。就像闪烁一样。 请在下面找到使用Jquery无法获得正确的输出

<head runat="server"> 
    <title>Untitled Page</title> 
    <script type="text/javascript" src="scripts/jquery-1.4.1.min.js"></script> 
    <script type="text/javascript"> 

     $(document).ready(function() { 

      $("#Button1").click(function() { 

       $("p").css("background-color", "Yellow") 

      }); 

     }); 

    </script> 
</head> 


<body> 
    <form id="form1" runat="server"> 
    <div> 

     <asp:Button ID="Button1" runat="server" Text="Button" /> 
      <p>This Should be in <br/> 
       yellow</p> 

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

回答

2

它的代码,因为ASP.NET更改ID属性的东西可以解决。

如果您使用的是ASP.NET 4,请将ClientIDMode设置为AutoID

如果使用的是其他任何东西,改变你的选择使用"#<%= Button1.ClientID %>"

此外,返回false防止形式被postbacked。

+0

感谢它的工作 – Govind

1

试试这个:

 $("#<%=Button1.ClientID %>").click(function() { 

      $("p").css("background-color", "Yellow") 

     }); 

当按钮呈现在客户端上不会有ID = “Button1的”

0

变化:

$("#Button1").click(function() { 

$("#<%=Button1.ClientID%>").click(function() { 
0
$("input[id$='Button1']").click(function() { 
button click stuff here. 
});