ascx在aspx中,jquery失效或button没执行

ascx 内代码

 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ry_sel.ascx.cs" Inherits="WebApplication2.ry_sel" %>
  <script src="Jquery-1.8.3.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#divChkList :checkbox").each(function () {
                $(this).click(function () {
                    var $txtList = $("#txtList2");
                    if (this.checked) {
                        // $txtList.val($txtList.val() + $(this).next().text() + ",");
                        $txtList.val($txtList.val() + $(this).parent("span").attr("alt") + ",");
                    }
                    else {
                        $txtList.val($txtList[0].value.replace($(this).parent("span").attr("alt") + ',', ''));
                    }
                });
            });
        });
    </script>
  <div style="width:400px;height:300px;margin:0 auto;">
        <div id="divMulti">
            <asp:TextBox ID="txtList2" runat="server" Width="286px" TextMode="MultiLine"></asp:TextBox>
            <div id="divChkList">
                <asp:CheckBoxList ID="chkList" runat="server" RepeatLayout="Table" RepeatDirection="Vertical">
                </asp:CheckBoxList>
            </div>
        </div>
    </div>

aspx 引用ascx:

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<%@ Register  Src="~/ry_sel.ascx" TagName="RySel" TagPrefix="uc2" %>
<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <uc2:RySel ID="RySel" runat="server"  />
    </div>
    </form>
</body>
</html>

1个回答

 var $txtList = $("#txtList2");

===>
var $txtList = $("#<%=txtList2.ClientID%>");
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问