文档(Documentation)
Easyui的每个组件都由属性、方法和时间组成。用户可以很方便的扩展easyui。
属性(Properties)
属性是在jQuery.fn.{plugin}.defaults中定义的。比如,比如对话框(dialog)的属性是定义在jQuery.fn.dialog.defaults中的。
事件(Events)
事件(即回调方法)是定义在jQuery.fn.{plugin}.defaults中的。
方法(Methods)
调用方法的语法:$('selector').plugin('method', parameter,2);
解释:
Selector就是jquery对象选择器
Plugin是插件的名字
Method是现有插件对应的方法
Parameter即参数对象,可以是对象,字符串,…
方法在jQuery.fn.{plugin}.methods中被定义。每一个组件都有2个参数:jq和param。第一个参数jq是必须的,他指的是jquery对象。第二个参数就是通过方法传递的参数。比如,为对话框组件扩展一个名叫“mymove”的方法,代码可能类似下面那样:
$.extend($.fn.dialog.methods, {
mymove: function(jq, newposition){
return jq.each(function(){
$(this).dialog('move', newposition,2);
},2);
}
},2);
那么现在你可以调用“mymove”方法移动对话框到指定的位置:
$('#dd').dialog('mymove', {
left: 200,
top: 100
},2);
开始使用jquery easyui
下载easyui的库,并css和javascript文件包含到你的页面中
<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
<script type="text/javascript" src="easyui/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
一旦你在页面中包含了easyui的必要文件,你就可以通过html标签(markup)或使用javascript定义easyui的组件。比如,定义一个可折叠功能的面板(panel),你可以写类似下面的html代码。
<div id="p" class="easyui-panel" style="width:500px;height:200px;padding:10px;"
title="My Panel" iconCls="icon-save" collapsible="true">
The panel content
</div>
当通过html标签定义一个组件,自从1.3版本以后的easyui,“data-options”属性可以用来支持html,因此可以重写上面的代码
<div id="p" class="easyui-panel" style="width:500px;height:200px;padding:10px;"
title="My Panel" data-options="iconCls:'icon-save',collapsible:true">
The panel content
</div>
下面的代码展示了怎么创建一个绑定“onSelect”事件的下拉组合框
<input class="easyui-combobox" name="language"
data-options="
url:'combobox_data.json',
valueField:'id',
textField:'text',
panelHeight:'auto',
onSelect:function(record){
alert(record.text)
}">