Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery和Web服务器控件_Jquery - Fatal编程技术网

Jquery和Web服务器控件

Jquery和Web服务器控件,jquery,Jquery,我正在学习jQuery,作为其中的一部分,我尝试了以下代码。。这是一个简单的练习,看看我是否可以使用Jquery操作服务器控件 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestForm.aspx.cs" Inherits="TestForm" %> <!DOCTYPE html> <html> <head> <title></title> &

我正在学习jQuery,作为其中的一部分,我尝试了以下代码。。这是一个简单的练习,看看我是否可以使用Jquery操作服务器控件

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestForm.aspx.cs"     Inherits="TestForm" %>
<!DOCTYPE html>
<html>
<head>
<title></title>
  <script src="http://code.jquery.com/jquery-1.5.js" type="text/jscript"></script>
</head>
<body>

  <p>Hello</p>
  <a href="#">Click to hide me too</a>
  <p>Here is another paragraph</p>
  <input id="HTMLButton" type="button" value="HTML Button"  />

<script type="text/jscript" >
  //Desired Behavior. The Command button outside Form Attribute works are desired. 
  $("input").click(function () {
    $("#NameText").toggle()
  });

  $("#<%=WebCtrlJScript.ClientID%>").click(function () {
    alert("Button btnToggleDiv from Name Clicked");
    $("#NameText").toggle();
  });

  //This is simple HTML button inside Form Element.
  $("#HTMLInsideForm").click(function () {
    alert("Button HTMLInsideForm Clicked");
      $("#NameText").toggle()
  });


</script>

<script type="text/javascript">
  function NameText() {
    alert("WebCtrlOnClientClick Clicked");
    $("#NameText").hide();
    this.blur();
  }

</script>
<form id="Form1" runat="server">
<div id="NameText">
  <table>
    <tr>
      <td>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
      </td>
      <td>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      </td>
    </tr>
  </table>
</div>
<div>
  <asp:Button ID="WebCtrlOnClientClick" runat="server" Text=".Net Button" OnClientClick="NameText()"/>
  <asp:Button ID="WebCtrlJScript" runat="server" Text="JScript Button"/>
  <input id="HTMLInsideForm" type="button" value="HTML Button(Inside Div)" />
</div>
</form>
</body>
</html>       

你好

这是另一段

//期望的行为。需要表单属性外部的命令按钮。 $(“输入”)。单击(函数(){ $(“#NameText”).toggle() }); $(“#”)单击(函数(){ 警报(“单击名称的按钮btntoglediv”); $(“#NameText”).toggle(); }); //这是表单元素中的简单HTML按钮。 $(“#HTMLInsideForm”)。单击(函数(){ 警报(“单击HTMLInsideForm按钮”); $(“#NameText”).toggle() }); 函数名text(){ 警报(“WebCtrlOnClientClick单击”); $(“#NameText”).hide(); 这个。blur(); }
似乎我的表单标签里的任何东西都不起作用。。例如,带有value=“HTML button”的第一个按钮可以使用ID=“NameText”切换div元素,而其他按钮无论是HTML还是服务器控件都无法隐藏div。我不确定缺少什么

谢谢 CSC

您需要使用

$('#')…


除非您使用的是.NET4.0。在这种情况下,您可以使用此处提供的解决方案:

Ugh,当您删除并重新添加您的注释时,我正在添加一个关于ASP.Net 4.0的响应,导致堆栈溢出。但我同意这是最正确的路线。对不起。我正在尝试您的解决方案。您的意思是$('#'+)。单击(函数(){alert(“Calling”)});对不起,它坏了。我肯定我可能做错了什么。这是我试过的$(“#”+)。单击(函数(){$(“#名称文本”).toggle()});谢谢你的帮助。您的解决方案修复了编译错误,但仍然无法按我希望的方式工作。我所期望的是,当我点击Button1时,ID=“NameText”的div标记中的所有内容都应该像ID=“HTML button”的按钮一样切换。