jQuery EasyUI 表單– 創建樹形下拉框(ComboTree)
樹形下拉框(ComboTree)是一個帶有下列樹形結構(Tree)的下拉框(ComboBox)。 它可以作為一個表單字段進行使用,可以提交給遠程服務器。
在本教程中,我們將要創建一個註冊表單,帶有name、address、city 字段。 city 字段是一個樹形下拉框(ComboTree)字段,在裡面用戶可以下拉樹面板(tree panel),並選擇一個特定的城市。
創建表單(Form)
<div id="dlg" class="easyui-dialog" style="width:500px;height:250px;padding:10px 30px;" title="Register" buttons="#dlg-buttons"> <h2>Account Information</h2> <form id="ff" method="post"> <table> <tr> <td>Name:</td> <td><input type="text" name="name" style="width:350px;"/></td> </tr> <tr> <td>Address:</td> <td><input type="text" name="address" style="width:350px;"/></td> </tr> <tr> <td>City:</td> <td><select class="easyui-combotree" url="data/city_data.json" name="city" style="width:156px;"/></td> </tr> </table> </form> </div> <div id="dlg-buttons"> <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="savereg()">Submit</a> <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a> </div>
從上面的代碼可以看到,我們為一個名為'city' 的樹形下拉框(ComboTree)字段設置了一個url 屬性,這個字段可以從遠程服務器檢索樹形結構(Tree)數據。 請注意,這個字段有一個樣式名字叫'easyui-combotree',所以我們不需要寫任何的js 代碼,樹形下拉框(ComboTree)字段將自動渲染。