Application (basic) ---- Easyui, basic ---- easyui
I ,.
2. source code.
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> Basic CRUD Application-jQuery EasyUI CRUD Demo </title>
<Link rel = "stylesheet" type = "text/css" href = "http://www.jeasyui.com/easyui/themes/default/easyui.css">
<Link rel = "stylesheet" type = "text/css" href = "http://www.jeasyui.com/easyui/themes/icon.css">
<Link rel = "stylesheet" type = "text/css" href = "http://www.jeasyui.com/easyui/themes/color.css">
<Link rel = "stylesheet" type = "text/css" href = "http://www.jeasyui.com/easyui/demo/demo.css">
<Script type = "text/javascript" src = "http://code.jquery.com/jquery-1.6.min.js"> </script>
<Script type = "text/javascript" src = "http://www.jeasyui.com/easyui/jquery.easyui.min.js"> </script>
</Head>
<Body>
<H2> Basic CRUD Application <P> Click the buttons on datagrid toolbar to do crud actions. </p>
<Table id = "dg" title = "My Users" class = "easyui-datagrid" style = "width: 700px; height: 250px"
Url = "http://www.jeasyui.com/demo/main/get_users.php"
Toolbar = "# toolbar" pagination = "true"
Rownumbers = "true" fitColumns = "true" singleSelect = "true">
<Thead>
<Tr>
<Th field = "firstname" width = "50"> First Name </th>
<Th field = "lastname" width = "50"> Last Name </th>
<Th field = "phone" width = "50"> Phone </th>
<Th field = "email" width = "50"> Email </th>
</Tr>
</Thead>
</Table>
<Div id = "toolbar">
<A href = "javascript: void (0)" class = "easyui-linkbutton" iconCls = "icon-add" plain = "true" onclick = "newUser () "> New User </a>
<A href = "javascript: void (0)" class = "easyui-linkbutton" iconCls = "icon-edit" plain = "true" onclick = "editUser () "> Edit User </a>
<A href = "javascript: void (0)" class = "easyui-linkbutton" iconCls = "icon-remove" plain = "true" onclick = "destroyUser () "> Remove User </a>
</Div>
<Div id = "dlg" class = "easyui-dialog" style = "width: 400px; height: 280px; padding: 10px 20px"
Closed = "true" buttons = "# dlg-buttons">
<Div class = "ftitle"> User Information </div>
<Form id = "fm" method = "post" novalidate>
<Div class = "fitem">
<Label> First Name: </label>
<Input name = "firstname" class = "easyui-textbox" required = "true">
</Div>
<Div class = "fitem">
<Label> Last Name: </label>
<Input name = "lastname" class = "easyui-textbox" required = "true">
</Div>
<Div class = "fitem">
<Label> Phone: </label>
<Input name = "phone" class = "easyui-textbox">
</Div>
<Div class = "fitem">
<Label> Email: </label>
<Input name = "email" class = "easyui-textbox" validType = "email">
</Div>
</Form>
</Div>
<Div id = "dlg-buttons">
<A href = "javascript: void (0)" class = "easyui-linkbutton c6" iconCls = "icon-OK" onclick = "saveUser ()" style = "width: 90px "> Save </a>
<A href = "javascript: void (0)" class = "easyui-linkbutton" iconCls = "icon-cancel" onclick = "javascript: $ ('# dlg '). dialog ('close') "style =" width: 90px "> Cancel </a>
</Div>
<Script type = "text/javascript">
Var url;
Function newUser (){
$ ('# Dlg'). dialog ('open'). dialog ('settitle', 'new user ');
$ ('# Fm'). form ('clear ');
Url = 'HTTP: // www.jeasyui.com/demo/main/save_user.php ';
}
Function editUser (){
Var row = $ ('# dg'). datagrid ('getselected ');
If (row ){
$ ('# Dlg'). dialog ('open'). dialog ('settitle', 'edit user ');
$ ('# Fm'). form ('load', row );
Url = 'HTTP: // www.jeasyui.com/demo/main/update_user.php? Id = '+ row. id;
Alert (row. id );
}
}
Function saveUser (){
Alert ('1 ');
$ ('# Fm'). form ('submit ',{
Url: url,
OnSubmit: function (){
Return $ (this). form ('validate ');
},
Success: function (result ){
Alert (result );
Var result = eval ('+ result + ')');
If (result. errorMsg ){
$. Messager. show ({
Title: 'error ',
Msg: result. errorMsg
});
} Else {
$ ('# Dlg'). dialog ('close'); // close the dialog
$ ('# Dg'). datagrid ('reload'); // reload the user data
}
},
Error: function (index ){
Alert (index );
}
});
}
Function destroyUser (){
Var row = $ ('# dg'). datagrid ('getselected ');
If (row ){
$. Messager. confirm ('Confirm', 'Are you sure you want to destroy this user? ', Function (r ){
If (r ){
$. Post ('HTTP: // www.jeasyui.com/demo/main/destroy_user.php', then id:row.id},function (result ){
If (result. success ){
$ ('# Dg'). datagrid ('reload'); // reload the user data
} Else {
$. Messager. show ({// show error message
Title: 'error ',
Msg: result. errorMsg
});
}
}, 'Json ');
}
});
}
}
</Script>
<Style type = "text/css">
# Fm {
Margin: 0;
Padding: 10px 30px;
}
. Ftitle {
Font-size: 14px;
Font-weight: bold;
Padding: 5px 0;
Margin-bottom: 10px;
Border-bottom: 1px solid # ccc;
}
. Fitem {
Margin-bottom: 5px;
}
. Fitem label {
Display: inline-block;
Width: 80px;
}
. Fitem input {
Width: 160px;
}
</Style>
</Body>
</Html>