kehua668 2016-07-04 07:32 采纳率: 25%
浏览 998

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条回答 默认 最新

  • Go 旅城通票 2016-07-04 07:41
    关注
     var $txtList = $("#txtList2");
    
    ===>
    var $txtList = $("#<%=txtList2.ClientID%>");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法