使用JQ时弹不出删除框,修改框取不到原有数据
<head runat="server">
<title>著作管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../content/themes/default/easyui.css" rel="stylesheet" type="text/css" />
<link href="../content/themes/icon.css" rel="stylesheet" type="text/css" />
<link href="../content/themes/demo.css" rel="stylesheet" type="text/css" />
<script src="../content/jquery-1.6.min.js" type="text/javascript"></script>
<script src="../content/jquery.easyui.min.js" type="text/javascript"></script>
<script src="../content/plugins/jquery.datagrid.js" type="text/javascript"></script>
<script src="../content/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#tt').datagrid({
nowrap: false,
striped: true,
toolbar: "#toolbar",
url: 'bookdata.aspx',
sortName: 'code',
sortOrder: 'desc',
fit: true,
columns: [[
{ field: 'BookNo', title: '书号', width: 150 },
{ field: 'BookName', title: '著作名称', width: 80 },
{ field: 'AuthorName', title: '作者', width: 80 },
{ field: 'AuthorSort', title: '作者排序', width: 80 },
{ field: 'BookDuties', title: '著作职务', width: 80 },
{ field: 'JobTitleName', title: '作者职称', width: 100 },
{ field: 'DempName', title: '部门名称', width: 150 },
{ field: 'PublicationDate', title: '出版时间', width: 120 },
{ field: 'PressName', title: '出版社', width: 180 },
{ field: 'PublicationPlace', title: '出版地', width: 80 },
{ field: 'BookWords', title: '撰写字数', width: 80 },
{ field: 'BookType', title: '著作类型', width: 80 },
{ field: 'BookEdition', title: '著作版次', width: 80 }
]],
onHeaderContextMenu: function (e, field) {
e.preventDefault();
if (!$('#tmenu').length) {
createColumnMenu();
}
$('#tmenu').menu('show', {
left: e.pageX,
top: e.pageY
});
}
});
});
function createColumnMenu() {
var tmenu = $('<div id="tmenu" style="width:100px;"></div>').appendTo('body');
var fields = $('#tt').datagrid('getColumnFields');
for (var i = 0; i < fields.length; i++) {
$('<div iconCls="icon-ok"/>').html(fields[i]).appendTo(tmenu);
}
tmenu.menu({
onClick: function (item) {
if (item.iconCls == 'icon-ok') {
$('#tt').datagrid('hideColumn', item.text);
tmenu.menu('setIcon', {
target: item.target,
iconCls: 'icon-empty'
});
} else {
$('#tt').datagrid('showColumn', item.text);
tmenu.menu('setIcon', {
target: item.target,
iconCls: 'icon-ok'
});
}
}
});
}
</script>
</head>
//增、删、改的按键
<div id="toolbar" >
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addbook()">增 加</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editbook()">修 改</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删 除</a>
</div>
//绑定数据
<div id="tt" idField="bookno" rownumbers="true" pagination="true" pageSize="10" pageList="[10,20,30,40,50]">
</div>
//这是引用JQ里的window框架
<div id="dlg" class="easyui-window" style="width:700px;height:400px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
//这是个框,就是点击修改时弹出来的框<div id="dlg" title="增加/修改数据" style="width:700px;height:400px;">
<div style="padding:10px 20px 5px 10px;">
<form method="post" id="fm" enctype="multipart/form-data">
<table>
</table>
<div>
<div>
<div>
//点击修改、删除时触发
<script type="text/javascript">
function editbook() {
$('#dlg').dialog('open').dialog('setTitle', '修改著作信息');
//$('#fm').form('clear');
var row = $('#dg').datagrid('getSelected');
if (row) {
$('#dlg').dialog('open').dialog('setTitle', '编辑著作信息');
$('#fm').form('load', row);
url = 'updateuserweb.aspx?BookNo=' + row.id;
}
}
function destroyUser() {
var row = $('#dg').datagrid('getSelected');
if (row) {
var index = $('#dg').datagrid('getRowIndex', row);
$.messager.confirm('温馨提示', '你确定要删除这个用户?',
function (r) {
if (r) {
// url = 'deluser.aspx?UserID=' + row.id;
$.post('bookdelete.aspx', { 'id': row.bookno },
function (result) {
if (result == "true") {
$.messager.show({ title: '温馨提示',
msg: '删除成功',
timeout: 3000,
showType: 'slide'
});
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({ // show error message
title: '错误',
msg: result.errorMsg
});
}
});
}
});
}
}
</script>
如上所述,点击删除时没有反应,点击羞改时也取不到已存在的数据。
不是很懂这种做法,因为第一次用,求各位大侠帮忙解决。
已经调试过function destroyUser() {alert("delete"); }
运行时点击删除弹出delete.
[解决办法]
这代码,太麻烦了,没时间看