easyui data-options

1. 使用 data-options 來初始化屬性。

 

data-options是jQuery Easyui 最近兩個版本才加上的一個特殊屬性。通過這個屬性,我們可以對easyui組件的實例化可以完全寫入到html中,例如:

<div class="easyui-dialog" style="width:400px;height:200px"
    data-options="title:'My Dialog',collapsible:true,iconCls:'icon-ok',onOpen:function(){}">
    dialog content.
</div>

屬性,事件,都可以直接寫在data-options裏面,這樣就方便多了。

 來自:http://easyui.btboys.com/the-use-of-easyui-data-options.html

 

2.  tools定義工具欄,繼承自panel的應該都可以使用。

複製代碼
$('#p').panel({   
    width:500,   
    height:150,   
    title: 'My Panel',   
   tools: [{   
     iconCls:'icon-add',   
     handler:function(){alert('new')}   
    },{   
     iconCls:'icon-save'  
     handler:function(){alert('save')}   
   }]   
}); 
複製代碼

tools 同樣可以加到data-options裏面。

 

3.  easyui 裏面的組件屬性,同樣可以寫在標籤裏面。

複製代碼
<div id="p" class="easyui-panel" title="My Panel" style="width:500px;height:150px;padding:10px;background:#fafafa;"  
          iconCls="icon-save"  closable="true"  
          collapsible="true" minimizable="true" maximizable=true>  
      <p>panel content.</p>  
      <p>panel content.</p>  
</div>  
複製代碼

data-options和這裏效果是一樣,但是API裏面大部分是按照屬性來定義標籤的,就想早先的HTML,而data-options就想style定義樣式,不知道這兩種有什麼優劣。

 

 4. 繼承

 

複製代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="easyui/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <link href="easyui/themes/gray/easyui.css" rel="stylesheet" type="text/css" />
    <link href="easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $('#dd').dialog({
                title: "My Dialog",
                modal: true, //dialog繼承自window,而window裏面有modal屬性,所以dialog也可以使用
                collapsible: true, //是否可摺疊,默認false
                minimizable: false, //是否可最小化,默認false
                maximizable: true, //是否可最大化,默認false
                resizable: true, //是否可摺疊,默認false
                toolbar: [{
                    iconCls: 'icon-add',
                    handler: function () { alert('new') }
                }, {
                    iconCls: 'icon-save',
                    handler: function () { alert('save') }
                }],
                buttons: [{
                    iconCls: 'icon-add',
                    handler: function () { alert('new') }
                }, {
                    iconCls: 'icon-save',
                    handler: function () { alert('save') }
                }],
                //繼承自panel,tool只有下面兩個屬性
                tools: [{
                    iconCls: 'icon-add',
                    handler: function () { alert('new') }
                }, {
                    iconCls: 'icon-save',
                    handler: function () { alert('save') }
                }]
            });
        })
    </script>
</head>
<body>
    <div id="dd" style="width: 500px; height: 400px;">
        Dialog Content.
    </div>
</body>
</html>
複製代碼

實現效果就是這樣的!



http://www.cnblogs.com/yokoboy/archive/2012/12/06/2806132.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章