日期:2014-05-17  浏览次数:20569 次

为什么我jquery 绑定ID 的click事件无效
C# code

foreach (var item in Model)
                        {
                            if (item.CurrentRootId != Guid.Empty)
                            {
                        <tr id="node-@item.CatalogId" class="child-of-node-@item.CurrentRootId">
                            <td>
                                @if (item.CatalogVoucher == "page" || item.CatalogVoucher == "Product")
                                {
                                    <span class="file">@Html.Encode(item.CatalogName)</span>
                                }
                                else
                                { 
                                    <span class="folder">@Html.Encode(item.CatalogName)</span>
                                }
                            </td>
                            <td>
                                @Html.Encode(item.NavigationLicence)
                            </td>
                            <td>
                                <span id="btn-edit"></span><a href="#" class="btn_edit" categoryid="@item.CatalogId">Edit</a> 
                                <span id="btn-delete"></span><a href="#" class="btn_delete" categoryid="@item.CatalogId"> Delete</a>
                            </td>
                        </tr>
                            }
                            else
                            {
                        <tr id="node-@item.CatalogId">
                            <td>
                                @if (item.CatalogVoucher == "page" || item.CatalogVoucher == "Product")
                                {
                                    <span class="file">@Html.Encode(item.CatalogName)</span>
                                }
                                else
                                { 
                                    <span class="folder">@Html.Encode(item.CatalogName)</span>
                                }
                            </td>
                            <td>
                                @Html.Encode(item.NavigationLicence)
                            </td>
                            <td>
                                <span id="btn-edit"></span><a href="#"  class="btn_edit" categoryid="@item.CatalogId">Edit</a>  
                                <span id="btn-delete"></span><a href="#" class="btn_delete" categoryid="@item.CatalogId">Delete</a>
                            </td>
                        </tr>
                            }
                        }




JScript code

 $(".btn-edit").click(function () {
        var id = $(this).attr('categoryId'); //取记录ID
        alert('111');
        $.ajax({
            //target address
            url: "Catalogs/GetCategory/" + id,
            //post transmission
            type: "POST",
            //data format:JSON 
            dataType: 'json',
            //beforeSend: function() { },
            success: function (result) {
                var jsondata = eval('(' + result + ')').category;
                if (jsondata != null) {
                    $.each(jsondata, function (i, item) {
                        $('#edit_id').val(i