使用较新版本的jquery获取未捕获的TypeError
我正在学习如何使用webgrid和jquery建立父子关系。 这是webgrid使用较新版本的jquery获取未捕获的TypeError,jquery,jquery-ui,Jquery,Jquery Ui,我正在学习如何使用webgrid和jquery建立父子关系。 这是webgrid <div id="main" style="padding:25px; background-color:white;"> @grid.GetHtml( htmlAttributes: new {id="gridT", width="700px" }, columns:grid.Columns(
<div id="main" style="padding:25px; background-color:white;">
@grid.GetHtml(
htmlAttributes: new {id="gridT", width="700px" },
columns:grid.Columns(
grid.Column("order.OrderID","Order ID"),
grid.Column(header:"Order Date",format:(item)=> string.Format("{0:dd-MM-yyyy}",item.order.OrderDate)),
grid.Column("order.CustomerName","Customer Name"),
grid.Column("order.CustomerAddress","Address"),
grid.Column(format:(item)=>{
WebGrid subGrid = new WebGrid(source: item.orderDetails);
return subGrid.GetHtml(
htmlAttributes: new { id="subT" },
columns:subGrid.Columns(
subGrid.Column("Product","Product"),
subGrid.Column("Quantity", "Quantity"),
subGrid.Column("Rate", "Rate"),
subGrid.Column("Amount", "Amount")
)
);
})
)
)
</div>
我试着把这个改成“.on”,但还是没有成功。我正在使用jquery-1.10.2。我如何才能做到这一点?和多年前被弃用并随后被删除。新方法是使用。如何在此代码中应用on?对我不起作用$(“.hoverEff”,this).on(“click”,function(){我正在学习这个。@user2320476:on(和
live
,和委托
)的文档在
上显示如何使用的清晰示例,您以前使用的是live
和delegate
。如果您正在学习,首先要学习的是文档是您的朋友。:-$(文档)。on(“click”,“.hoverEff”,function(){/*…*/};
我尝试了这个方法,但不起作用。$(文档)。on(“click”,“.hoverEff”,function(){$(this.parent().next().slideToggle(100);$(this.toggleClass(“expand-collapse”);};@user2320476:对不起,我误读了原始代码,它使用了$(.hoverEff),this)
语法,我希望它们能从jQuery中删除(有人说他们很可能会这么做。)所以:$(这个)。在(“click”、“.hoverEff”、function(){/*…*/});
或者类似的东西上。再次强调:文档是你的朋友。请阅读live
,以及上的,你将能够将一个文档翻译成另一个文档。
@section Scripts{
<script>
$(document).ready(function () {
var size = $("#main #gridT > thead > tr >th").size(); // get total column
$("#main #gridT > thead > tr >th").last().remove(); // remove last column
$("#main #gridT > thead > tr").prepend("<th></th>"); // add one column at first for collapsible column
$("#main #gridT > tbody > tr").each(function (i, el) {
$(this).prepend(
$("<td></td>")
.addClass("expand")
.addClass("hoverEff")
.attr('title',"click for show/hide")
);
//Now get sub table from last column and add this to the next new added row
var table = $("table", this).parent().html();
//add new row with this subtable
$(this).after("<tr><td></td><td style='padding:5px; margin:0px;' colspan='" + (size - 1) + "'>" + table + "</td></tr>");
$("table", this).parent().remove();
// ADD CLICK EVENT FOR MAKE COLLAPSIBLE
$(".hoverEff", this).live("click", function () {
$(this).parent().closest("tr").next().slideToggle(100);
$(this).toggleClass("expand collapse");
});
});
//by default make all subgrid in collapse mode
$("#main #gridT > tbody > tr td.expand").each(function (i, el) {
$(this).toggleClass("expand collapse");
$(this).parent().closest("tr").next().slideToggle(100);
});
});
</script>
}
$(".hoverEff", this).live("click", function () {
$(this).parent().closest("tr").next().slideToggle(100);
$(this).toggleClass("expand collapse");
});