jquery easyui(如何使用jQuery EasyUI打造Web程序)
大家好,关于jquery easyui很多朋友都还不太明白,今天小编就来为大家分享关于如何使用jQuery EasyUI打造Web程序的知识,希望对各位有所帮助!
如何使用jQuery EasyUI打造Web程序
1
在百度搜索引擎中搜索“jQuery EasyUI”关键词,如下图所示。
2
访问JQuery EasyUI中文网,如下图所示。
3
点击导航栏上的【JQuery EasyUI下载】超链接,访问JQuery EasyUI下载页面,如下图所示。
4
选择GPL版本,点击下方的【官方下载】按钮,如下图所示。
5
解压JQuery EasyUI GPL版本,工程目录如下图所示。
6
以下用一个Basic CRUD Application(基本增删改查应用程序)为例,来介绍JQuery EasyUI的用法。、
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic CRUD Application- jQuery EasyUI CRUD Demo</title>
<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" href="http://www.jeasyui.com/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" href="http://www.jeasyui.com/easyui/themes/color.css">
<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" 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</h2>
<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="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 rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="javascript:void(0)" class="easyui-linkbutton"
iconCls="icon-add" plain="true" onclick="newUser()">New
User</a>
<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="javascript:void(0)"
class="easyui-linkbutton" iconCls="icon-edit" plain="true"
onclick="editUser()">Edit User</a>
<a
rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" 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 rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="javascript:void(0)" class="easyui-linkbutton c6"
iconCls="icon-ok" onclick="saveUser()"
style="width:90px">Save</a>
<a
rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" 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('center').dialog('setTitle','New User');
$('#fm').form('clear');
url='save_user.php';
}
function editUser(){
var row=$('#dg').datagrid('getSelected');
if(row){
$('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit User');
$('#fm').form('load',row);
url='update_user.php?id='+row.id;
}
}
function saveUser(){
$('#fm').form('submit',{
url: url,
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');// close the dialog
$('#dg').datagrid('reload');// reload the user data
}
}
});
}
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('destroy_user.php',{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>
7
该案例运行效果,如下图所示。
8
在该案例中,需要引入以下CSS和js文件,如下所示:
<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" href="http://www.jeasyui.com/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" href="http://www.jeasyui.com/easyui/themes/color.css">
<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" 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>
jQuery EasyUI API 中文文档 - Documentation 文档
每个easyui组件都有特性(property)、方法(method)和事件(event),用户可以很容易地扩展它们。
特性
特性在jQuery.fn.{plugin}.defaults里定义。例如,
dialog的特性在jQuery.fn.dialog.defaults里定义。
事件
事件(回调函数)也在jQuery.fn.{plugin}.defaults里定义。
方法
方法在jQuery.fn.{plugin}.methods里定义。每个方法有两个参数:jq和param。第一个参数'jq'是必须的,它是指jQuery对象。第二个参数'param'
是指传递给方法的真正的参数。例如,给dialog组件扩展一个名叫'mymove'
的方法,代码看起来就像这样:
复制代码
代码如下:
$.extend($.fn.dialog.methods,
{
mymove:
function(jq,
newposition){
return
jq.each(function(){
$(this).dialog('move',
newposition);
});
}
});
现在你可以调用'mymove'方法把dialog移动到一个指定的位置:
复制代码
代码如下:
$('#dd').dialog('mymove',
{
left:
200,
top:
100
});
JQuery-EasyUI与EXTjs有什么区别
一、ExtJS
1、ExtJS可以用来开发RIA也即富客户端的AJAX应用,是一个用javascript写的,主要用于创建前端用户界面,是一个与后台技术无关的前端ajax框架。因此,可以把ExtJS用在.Net、Java、Php等各种开发语言开发的应用中。ExtJs最开始基于YUI技术,由开发人员JackSlocum开发,通过参考JavaSwing等机制来组织可视化组件,无论从UI界面上CSS样式的应用,到数据解析上的异常处理,都可算是一款不可多得的JavaScript客户端技术的精品。
2、Ext的UI组件模型和开发理念脱胎、成型于Yahoo组件库YUI和Java平台上Swing两者,并为开发者屏蔽了大量跨浏览器方面的处理。相对来说,EXT要比开发者直接针对DOM、W3C对象模型开发UI组件轻松。
二、JQuery
jQuery是一个兼容多浏览器的javascript框架,核心理念是write less,do more(写得更少,做得更多)。jQuery在2006年1月由美国人John Resig在纽约的barcamp发布,吸引了来自世界各地的众多JavaScript高手加入,由Dave Methvin率领团队进行开发。如今,jQuery已经成为最流行的javascript框架,在世界前10000个访问最多的网站中,有超过55%在使用jQuery。
jQuery是免费、开源的,使用MIT许可协议。jQuery的语法设计可以使开发者更加便捷,例如操作文档对象、选择DOM元素、制作动画效果、事件处理、使用Ajax以及其他功能。除此以外,jQuery提供API让开发者编写插件。其模块化的使用方式使开发者可以很轻松的开发出功能强大的静态或动态网页。
三、二者对比
1.JQuery-EasyUI是仿照Ext做的。
2.Ext框架是一个整体,面向对象的编程思想,每个控件之间可以相互通讯。
3.JQuery的控件全都是分散的,没有整体性可言。你可以单独拿出来一个控件就能用。
4.若要开发系统应用,首选Ext,控件库丰富,扩展和维护都方便。若是简单的页面动画和效果,首选JQuery
5.jquery只是一个工具库,比较简单,相对容易。 Ext是一套真正的ria开发框架,甚至可以实现桌面应用一样的强大功能。本身代码质量极高,而且是高度的面向对象设计。jQuery入门相对容易一些,实际用的过程中要用到各种插件,基本上用一个“学”一个。 ExtJS入门稍难。
6.大小比较:首先ExtJS是一个完整的Framework,是重量级别的,easy ui是基于jquery库的一套UI组件库,是轻量级的,ExtJS是应用application级的,而jquery是page页面级的。当然application也是由page组成的,那就需要你自己去完成了,考虑你的需求,和使用框架的初衷,选择使用哪一种。同时ExtJs由于是重量级框架,完全面向对象风格,提供API非常完备也非常庞大,所以学习成本也想相对较大。
7.兼容性比较:ExtJS兼容IE全系列浏览器和其他非IE现代浏览器,jquery UI向来不太考虑ie低版本浏览器的兼容,从态度上的鄙视。easy UI是基于jquery的,jquery2.X以上的版本不再支持IE6、7、8,,已郑重声明,请看官方网站,easyUI最新版本1.3.3使jQuery2.0,由于又很多HTML5特性,不再支持IE6\7\8,低版本由一些小部分的兼容不够好,请自己做技术选型的时候去测试,要使用那个版本。在兼容问题上,都有瑕疵,主要看接收程度。
8.使用许可license. EXTJS 2.1以上版本,商用需要购买商业授权,jquery UI使用MIT协议,开源。 jquery easyUI如果商用需遵循license commercial商业许可,也就是要购买使用权。
jquery easyui和如何使用jQuery EasyUI打造Web程序的问题分享结束啦,以上的文章解决了您的问题吗?欢迎您下次再来哦!