easyui学习笔记1—增删改操作
最近公司要用easyui,这里自己看了官网几篇文章,遇到些问题,大多数的问题都是敲代码的时候笔误,其他有些地方确实需要注意一下,这里做些笔记。
1.在mysql中建好表之后修改id字段为递增字段,发现这个奇怪的mysql语法,如下
alter table student change id id int auto_increment;
这句是在student表已经建好的情况下来修改字段id为自增列,奇怪的是为嘛change id id,并且后面还要带上id的类型int?
2.html5标记
如何申明自己这个html文档是html5标准的呢,<!DOCTYPE html>就这句,根据w3c上的解释,只能是这一句
3.定义一个 表格的语法如下
<!--定义一个表格-->
<table id="dg" title="My User" class="easyui-datagrid" style="width:700px;height:250px"
url="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>
注意这里很多的标签元素是不符合html4的规范的url="get_users.php"这个,在html5里面才有用,在html4里面是不规范的,没有这个元素,toolbar="#toolbar"这个表示表格的工具栏,就是新加,删除,修改的操作。另外easyui自己定义了一套样式class="easyui-datagrid"这一句是easyui里面自定义的样式,在easyui里面还有很多风格的样式。
定义表格的工具栏如下:
<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>
这里面也有自定义标签,例如iconCls="icon-add"这个表示新增按钮。注意这里id="toolbar"这个不是随便定义的,要和上面的toolbar="#toolbar"保持一致。
点击新增和修改的时候要打开一个对话框,代码如下:
<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-validatebox" required="true" />
</div>
<div class="fitem">
<label>Last Name:</label>
<input name="lastname" class="easyui-validatebox" required="true" />
</div>
<div class="fitem"><label for="">Phone:</label>
<input name="phone" />
</div>
<div class="fitem">
<label for="">Email:</label><input type="" name="email" class="easyui-validatebox" validType="email" />
</div>
</form>
</div>
这里class="easyui-dialog"表示这个是一个对话框来着,buttons="#dlg-buttons"表示这个对话框下面的两个确认,取消按钮,这一这个名字也不是随便定义的。注意<div class="ftitle">User Information</div>这个其实原理很简单,就是定义了一个div,然后给了一个border-bottom: 1px solid #CCCCCC;
因为要和后台交互,在这个对话框里面装了一个form,里面的input元素有些需要进行验证,required="true"表示必须填写元素,validType="email"表示验证类型是emai验证,这里不知道能不能重写这个验证规则,class="easyui-validatebox"定义了验证失败后的提示
在对话框中的按钮定义在外面,代码如下:
<div id="dlg-buttons">
<a href="javascript:void(0)" class="easyui-linkbutton" icon-Cls="icon-ok" onclick="saveUser()">Save</a>
<a href="javascript:void(0)" class="easyui-linkbutton" icon-Cls="icon-cancel" onclick="javascript:$('#dlg').dialog('close');">Cancel</a>
</div>
这里id="dlg-buttons"名字要和对话框中的buttons="#dlg-buttons"保持一致的,icon-Cls="icon-ok" ,icon-Cls="icon-cancel"和上面的icon-Cls="icon-add",icon-Cls="icon-edit",icon-Cls="icon-remove"意思类似,都是按钮的样式。
以上全部都是html的定义。
4.js函数解析
和后台php交互需要使用javascript函数,这里也有很多地方需要注意,代码如下:
<script type="text/javascript">
var urls;
function newUser(){
$('#dlg').dialog('open').dialog('setTitle','New User');
$('#fm').form('clear');
urls = 'save_user.php';//为saveUser方法准备访问url,注意是全局变量
}
function editUser(){
var row = $("#dg").datagrid("getSelected");
if(row){
$("#dlg").dialog("open").dialog("setTitle","Edit User");
$("#fm").form("load",row);
urls = "update_user.php?id="+row.id;//为editUser方法准备访问url,注意是全局变量
}
}
function saveUser(){
$("#fm").form("submit",{
url:urls, //使用参数
onSubmit:function(){
return $(this).form("validate"); //提交前验证
},
success:function(result){
var result = eval('('+result+')');
if(result.errorMsg){
$.messager.show(
{
title:"Error",
msg:result.errorMsg
});
}
else{
$("#dlg").dialog("close");
$("#dg").datagrid("reload")
}
}
});
}
function destroyUser()
{
var row = $("#dg").datagrid("getSelected");
if(row)
{
$.messager.confirm("Confirm","Are you sure you want to destory this.user?",function(r)
{
if(r)
{
$.post('destory_user.php',{id:row.id},function(result){
if (result && result.success){
$('#dg').datagrid('reload'); //重新加载数据
} else {
$.messager.show({ //显示错误信息
title: 'Error',
msg: result.msg
});
}
},'json');
}
});
}
}
</script>
还有后台的php代码这里就不贴出来了,在这里犯了几个错误。
$conn = mysql_connect("localhost","host","Ctrip07185419") or die("can not connect to server");
这句是php中连接服务器的语句,但是报错 Access denied for user 'host'@'localhost' (using password: YES),很明显应该吧"host"换成"root"
$sql = "delete from student where id='$id'";这句是定义sql语句,但是也报错,其实应该这样写:
$sql = "delete from student where id=$id";
还有在执行完删除之后一直没有重新加载数据,怎么看都没有错误,返回值也是对的{"success":true},最后返现在destory_user.php里面有一个echo mysql_error()这句是用来调试的,但是会影响输出结果,后面还要输出执行语句的结果,如果语句中执行两次echo就会造成easyui不能识别输出的结果,造成截止,不能显示正确的结果。
easyui学习笔记1—增删改操作的更多相关文章
- 【.NET-EF】Entity Framework学习笔记2 - 增删改(没查询)
学习描述:用EF就像是省略了做实体类和DAL类,感觉是很方便,废话不多说,直接写步骤: 1.创建EF的edmx文件 这个其实在笔记1已说过,不过有些细节也要说,所以再说一遍,这里使用的是EF 6.1版 ...
- 3、MyBatis.Net学习笔记之增删改
增删改之前先说一下笔记1里提到的一个无法创建ISqlMapper对象的问题. <resultMaps> <resultMap id="FullResultMap" ...
- 【转载】ASP.NET MVC Web API 学习笔记---联系人增删改查
本章节简单介绍一下使用ASP.NET MVC Web API 做增删改查.目前很多Http服务还是通过REST或者类似RESP的模型来进行数据操作的.下面我们通过创建一个简单的Web API来管理联系 ...
- EF学习笔记——通用增删改查方案
http://blog.csdn.net/leftfist/article/details/25005307 我刚接触EF未久,还不知道它有什么强大之处,但看上去,EF提供了一般的增删改查功能.以往用 ...
- ASP.NET MVC Web API 学习笔记---联系人增删改查
本章节简单介绍一下使用ASP.NET MVC Web API 做增删改查. 目前很多Http服务还是通过REST或者类似RESP的模型来进行数据操作的. 下面我们通过创建一个简单的Web API来管理 ...
- MongoDB学习笔记,基础+增删改查+索引+聚合...
一 基础了解 对应关系 -> https://docs.mongodb.com/manual/reference/sql-comparison/ database -> database ...
- Mybatis学习笔记3 - 增删改查示例
1.接口定义 package com.mybatis.dao; import com.mybatis.bean.Employee; public interface EmployeeMapper { ...
- MongoDB学习笔记—03 增删改查操作
MongoDB的CURD操作分别通过函数insert().update().find().remove()进行 MongoDB文档新增与删除 MongoDB中关于文档的新增与删除比较简单.主要通过in ...
- PHP操作xml学习笔记之增删改查(2)—删、改、查
xml文件 <?xml version="1.0" encoding="utf-8"?><班级> <学生> ...
随机推荐
- JVM的内存分配和回收策略
对象的Class加载 虚拟机遇到一条new指令时,首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引用代表的类是否已被加载.解析和初始化过.如果没有,那必须先执行相应 ...
- mysql的线程处于System lock状态下
The thread has called mysql_lock_tables() and the thread state has not been updated since. This is a ...
- 100个实用的CSS技巧,以及遇见的问题和解决方案。
前言 本篇文章将会持续更新,我会将我遇见的一些问题,和我看到的实用的CSS技巧记录下来,本篇文章会以图文混排的方式写下去.具体什么时候写完我也不清楚,反正我的目标是写100个. 本案例都是经本人实测 ...
- MemcacheHelper.cs
using Memcached.ClientLibrary; using System; using System.Collections.Generic; using System.Linq; us ...
- [android] 界面切换的简单动画
1. 新建个位移动画的xml文件 Activity中开启动画 使用AnimationUtils类加载动画资源文件 left_to_right.xml <?xml version="1. ...
- Java基础(九)多线程
一.线程和进程 进程(Process): 1.是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础. 2.在早期面向进程设计的计算机结构中,进程是程 ...
- HttpServletResponse对象(二)之常见应用
---恢复内容开始--- 1. 使用HttpServletResponse对象实现文件下载 文件下载功能是web开发中经常使用到的功能,使用HttpServletResponse对象就可以实现文件的下 ...
- MySql中存储引擎MyISAM与InnoDB区别于选择
InnoDB: 支持事务处理等 不加锁读取 支持外键 支持行锁 不支持FULLTEXT类型的索引 不保存表的具体行数,扫描表来计算有多少行 DELETE 表时,是一行一行的删除 InnoDB 把数据和 ...
- Python入门教程
http://www.cnblogs.com/vamei/archive/2012/09/13/2682778.html
- 表格 滚动条 (tbody部分滚动)
本文是从简书复制的, markdown语法可能有些出入, 想看"正版"和更多内容请关注 简书: 小贤笔记 html <table> <thead> < ...