实际上我正在尝试使用c#开发拖放gridview,我已经找了一些像tableDnD这样的jquery库,并且按照一些例子我看到了一段代码。我试图用我的代码回复它,但我有一个
Uncaught TypeError: $(...).tableDnD is not a function.
我的代码很简单,我想解释一下:
首先,这是一个包含以下代码的母版页:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"></script>
<link rel="stylesheet" href="Styles/Coaching.css" type="text/css" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"/>
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous"/>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="http://localhost:2848/js/jquery.tablednd.js" type="js/javascript">
</script>
<script type="text/javascript">
var strorder;
$(document).ready(function () {
$('#grdResultados').tableDnD(
{
onDrop: function (table, row) {
reorder();
$.ajax({
type: "POST",
url: "diagnostico-plantilla.aspx/GridViewReorders",
data: '{"Reorder":"' + strorder + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg) {
alert("Successfully Save ReOrder");
}
})
}
}
);
});
function reorder() {
strorder = "";
var totalid = $('#grdResultados tr td input').length;
for (var i = 0; i < totalid; i++) {
strorder = strorder + $('#grdResultados tr td input')[i].getAttribute("value") + "|";
}
}
</script>
正如您所看到的那样,它是一个简单的母版页,那么aspx就有了我编写gridview的这一行
<asp:GridView ID="grdResultados" runat="server" CssClass="table table-hover" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" GridLines="None" DataKeyNames="id" DataSourceID="odsResultados" OnRowDataBound="grdResultados_RowDataBound" OnPageIndexChanged="grdResultados_PageIndexChanged" OnSorting="grdResultados_Sorting" OnRowCommand="grdResultados_RowCommand">
所以,为什么我会犯这个错误,因为当我尝试拖放时,它不起作用,我使用了Chrome检查器,而且我有这个。
非常感谢
答案 0 :(得分:0)
替换此行:
<script src="http://localhost:2848/js/jquery.tablednd.js" type="js/javascript">
有了这个:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/plugins/jquery.tablednd.js"></script>
如果这样可以解决问题,您就知道您没有正确引用tablednd.js
文件。添加对本地.js文件的引用的最简单方法是从Visual Studio - Solution Explorer拖动到该页面