4c3c0b92404f7aa238d66b0fc1bdee997c193e4f.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <title>单选下拉框</title>
  6. <!--框架必需start-->
  7. <script type="text/javascript" src="../../libs/js/jquery.js"></script>
  8. <script type="text/javascript" src="../../libs/js/language/cn.js"></script>
  9. <script type="text/javascript" src="../../libs/js/framework.js"></script>
  10. <link href="../../libs/css/import_basic.css" rel="stylesheet" type="text/css"/>
  11. <link rel="stylesheet" type="text/css" id="skin" prePath="../../"/>
  12. <link rel="stylesheet" type="text/css" id="customSkin"/>
  13. <!--框架必需end-->
  14. </head>
  15. <body>
  16. <div class="box1" panelWidth="800">
  17. <fieldset>
  18. <legend>1、json数据模式(json数据源)</legend>
  19. 使用url属性获取数据:
  20. <div class="red">此示例由后台支持</div>
  21. <!--
  22. <select prompt="请选择" url="../../userAction.do?method=getUsersOfListFormation" id="sel-1-1"></select>
  23. -->
  24. <br/>
  25. <input type="button" value="获取选中值" onclick="getSelectedItem()"/>
  26. <br/>
  27. <br/>
  28. 使用url属性+参数获取数据:
  29. <div class="red">此示例由后台支持</div>
  30. <!--
  31. <select url="../../userAction.do?method=getUsersOfListFormation" prompt="请选择员工" params='{"userinfor.organization.orgId":"3"}'></select>
  32. -->
  33. <br/>
  34. <br/>
  35. 赋值给标签的data属性:<br/>
  36. <select prompt="请选择员工" data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}'></select>
  37. <br/>注意:使用json格式的字符串时所有节点的属性名与值都必须使用双引号
  38. <br/>
  39. <br/>
  40. 动态设置data(本地数据源)<br/>
  41. <select prompt="请选择员工" id="sel-1-2" keepDefaultStyle="true"></select>
  42. <br/>
  43. <br/>
  44. 动态设置data(远程数据源)
  45. <div class="red">此示例由后台支持</div>
  46. <!--
  47. <select prompt="请选择员工" id="sel-1-3" keepDefaultStyle="true"></select>
  48. -->
  49. </fieldset>
  50. <div class="height_15"></div>
  51. <fieldset>
  52. <legend>2、本地模式</legend>
  53. <select>
  54. <option value="">请选择功能</option>
  55. <option value="0">新增图片</option>
  56. <option value="1">维护图片</option>
  57. <option value="2">新增新闻</option>
  58. </select>
  59. </fieldset>
  60. <div class="height_15"></div>
  61. <fieldset>
  62. <legend>3、禁用/启用</legend>
  63. <select disabled="true" id="sel-3" data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}'></select>
  64. <br/>
  65. <input type="button" value="启用" onclick="enableSelect()" style="width:105px;"/>
  66. <input type="button" value="禁用" onclick="disableSelect()" style="width:105px;"/>
  67. </fieldset>
  68. <fieldset>
  69. <legend>4、change事件</legend>
  70. 使用bind方法绑定change事件<br/>
  71. <select id="sel-4" data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}'></select>
  72. <br/>
  73. <br/>
  74. 也可以使用标签自带的onchange<br/>
  75. <select data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}' onchange="onchangeHandler(this)"></select>
  76. </fieldset>
  77. <div class="height_15"></div>
  78. <fieldset>
  79. <legend>5、使用optgroup进行分组(仅本地模式可以)</legend>
  80. <select>
  81. <option>请选择权限</option>
  82. <optgroup label="首页信息发布">
  83. <option value="新增图片">新增图片</option>
  84. <option value="维护图片">维护图片</option>
  85. <option value="新增新闻">新增新闻</option>
  86. </optgroup>
  87. <optgroup label="人员维护">
  88. <option value="新增用户">新增用户</option>
  89. <option value="用户列表">用户列表</option>
  90. </optgroup>
  91. </select>
  92. </fieldset>
  93. <div class="height_15"></div>
  94. <fieldset>
  95. <legend>6、宽度、高度与方向</legend>
  96. 下拉框默认为120px宽度,当有较长的选项时,下拉框宽度默认不变,而选项容器宽度自适应<br/>
  97. <select>
  98. <option value="">请选择功能</option>
  99. <option value="0">我是很长很长很长很长很长很长很长很长的选项</option>
  100. <option value="1">维护图片</option>
  101. <option value="2">新增新闻</option>
  102. </select>
  103. <br/><br/>
  104. 单独设置下拉框宽度,选项容器宽度默认不会小于下拉框宽度<br/>
  105. <select selWidth="260">
  106. <option value="">请选择功能</option>
  107. <option value="1">维护图片</option>
  108. <option value="2">新增新闻</option>
  109. </select>
  110. <br/><br/>自定义容器高度:<br/>
  111. <select boxHeight="100" data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"},{"value":"2","key":"员工2"},{"value":"2","key":"员工2"},{"value":"2","key":"员工2"},{"value":"2","key":"员工2"},{"value":"2","key":"员工2"},{"value":"2","key":"员工2"},{"value":"2","key":"员工2"}]}'></select>
  112. <br/><br/>强制向上展开:<br/>
  113. <select data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}' openDirection="top"></select>
  114. </fieldset>
  115. <div class="height_15"></div>
  116. <fieldset>
  117. <legend>7、可编辑</legend>
  118. <select data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}' editable="true" id="sel-7"></select><br/>
  119. <input type="button" value="获取值" onclick="getEditableValue()"/>
  120. </fieldset>
  121. <div class="height_15"></div>
  122. <fieldset>
  123. <legend>8、自定义列数</legend>
  124. <select colNum="3" colWidth="80" data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"},{"value":"3","key":"员工3"},{"value":"4","key":"员工4"},{"value":"5","key":"员工5"},{"value":"6","key":"员工6"}]}'></select>
  125. <br/><br/>
  126. </fieldset>
  127. <div class="height_15"></div>
  128. <fieldset>
  129. <legend>9、联动</legend>
  130. <div class="red">此示例由后台支持</div>
  131. <!--
  132. <table>
  133. <tr>
  134. <td>
  135. <select id="sel-9-1" url="../../organizationAction.do?method=getDepartments&parentid=0" prompt="请选择公司"
  136. childId="sel-9-2" childDataPath="../../organizationAction.do?method=getDepartments&parentid=" ></select>
  137. </td>
  138. <td>
  139. <select id="sel-9-2" prompt="请选择部门" childDataPath="../../userAction.do?method=getUsersOfListFormation&userinfor.organization.orgId="
  140. childId="sel-9-3"></select>
  141. </td>
  142. <td>
  143. <select id="sel-9-3" prompt="请选择员工"></select>
  144. </td>
  145. </tr>
  146. </table>
  147. <br/>
  148. <br/>
  149. 联动下拉框加载数据完成后的回调函数:
  150. <table>
  151. <tr>
  152. <td>
  153. <select id="sel-9-4" url="../../organizationAction.do?method=getDepartments&parentid=0" prompt="请选择公司"
  154. childId="sel-9-5" childDataPath="../../organizationAction.do?method=getDepartments&parentid=" ></select>
  155. </td>
  156. <td>
  157. <select id="sel-9-5" prompt="请选择部门" childDataPath="../../userAction.do?method=getUsersOfListFormation&userinfor.organization.orgId="
  158. childId="sel-9-6"></select>
  159. </td>
  160. <td>
  161. <select id="sel-9-6" prompt="请选择员工" ></select>
  162. </td>
  163. </tr>
  164. </table>
  165. <p>在这里监听第二个下拉框的加载完成事件,来重置第三个下拉框。</p>
  166. <br/>
  167. 初始时赋值
  168. <table>
  169. <tr>
  170. <td>
  171. <select id="sel-9-7" url="../../organizationAction.do?method=getDepartments&parentid=0" selectedValue="1" prompt="请选择公司"
  172. childId="sel-9-8" childDataPath="../../organizationAction.do?method=getDepartments&parentid=" ></select>
  173. </td>
  174. <td>
  175. <select id="sel-9-8" prompt="请选择部门" selectedValue="13"></select>
  176. </td>
  177. </tr>
  178. </table>
  179. -->
  180. <br/><br/><br/>
  181. 省市县三级联动
  182. <br/>
  183. 数据写在文件中,不读写数据库,减少服务器负担。<br/>
  184. <table>
  185. <tr>
  186. <td>
  187. <select id="sel-9-9" childId="sel-9-10" url="../../sample_html/form/area.xml" prompt="请选择省份" dataType="xml" childDataType="xml" dataRoot="province" labelField="name" valueField="name" openDirection="bottom"></select>
  188. </td>
  189. <td>
  190. <select id="sel-9-10" childId="sel-9-11" prompt="请选择城市" dataType="xml" childDataType="xml" dataRoot="city" labelField="name" valueField="name" openDirection="bottom"></select>
  191. </td>
  192. <td>
  193. <select id="sel-9-11" prompt="请选择区" dataType="xml" dataRoot="country" labelField="name" valueField="name" openDirection="bottom"></select>
  194. </td>
  195. </tr>
  196. </table>
  197. <br/>
  198. 初始时赋值<br/>
  199. <table>
  200. <tr>
  201. <td>
  202. <select id="sel-9-12" childId="sel-9-13" url="../../sample_html/form/area.xml" prompt="请选择省份" selectedValue="安徽省" dataType="xml" childDataType="xml" dataRoot="province" labelField="name" valueField="name" openDirection="bottom"></select>
  203. </td>
  204. <td>
  205. <select id="sel-9-13" childId="sel-9-14" prompt="请选择城市" selectedValue="宣城市" dataType="xml" childDataType="xml" dataRoot="city" labelField="name" valueField="name" openDirection="bottom"></select>
  206. </td>
  207. <td>
  208. <select id="sel-9-14" prompt="请选择区" selectedValue="宣州区" dataType="xml" dataRoot="country" labelField="name" valueField="name" openDirection="bottom"></select>
  209. </td>
  210. </tr>
  211. </table>
  212. </fieldset>
  213. <div class="height_15"></div>
  214. <fieldset>
  215. <legend>10、设置初始时选中值</legend>
  216. json数据模式:<br/>
  217. 使用selectedValue(推荐):<br/>
  218. <select data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}' selectedValue="2"></select><br/>
  219. 使用selectedIdx:<br/>
  220. <select data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}' prompt="请选择省份" selectedIdx="1"></select>
  221. <br/>
  222. 同一个组件不要既设置selectedIdx又设置selectedValue
  223. <br/><br/>本地模式:<br/>
  224. <select>
  225. <option value="">请选择功能</option>
  226. <option value="1" selected="selected">新增图片</option>
  227. <option value="2">维护图片</option>
  228. <option value="3">新增新闻</option>
  229. </select>
  230. </fieldset>
  231. <div class="height_15"></div>
  232. <fieldset>
  233. <legend>11、动态生成下拉框</legend>
  234. <div class="red">此示例由后台支持</div>
  235. <input type="button" value="点击生成(使用url)" id="testBtn" onclick="dynamicSelectbox1()" style="width:150px;"/><br/><br/>
  236. <div class="red">此示例由后台支持</div>
  237. <input type="button" value="点击生成(使用data)" id="testBtn2" onclick="dynamicSelectbox2()" style="width:150px;"/><br/><br/>
  238. <input type="button" value="点击生成本地下拉框" id="testBtn3" onclick="dynamicSelectbox3()" style="width:150px;"/>
  239. </fieldset>
  240. <div class="height_15"></div>
  241. <fieldset>
  242. <legend>12、动态修改下拉框</legend>
  243. json数据模式:<br/>
  244. <select prompt="请选择" data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}' id="sel-12-1"></select>
  245. <br/><br/><input type="button" value="选中“员工1”" onclick="selectSecondItem1()" style="width:105px;"/>
  246. <input type="button" value="追加一项" onclick="appendItem1()" style="width:105px;"/>
  247. <input type="button" value="移除“员工2”" onclick="removeItem1()" style="width:105px;"/>
  248. <br/>
  249. <br/><br/>
  250. 本地模式:<br/>
  251. <select id="sel-12-2">
  252. <option value="">请选择功能</option>
  253. <option value="0">新增图片</option>
  254. <option value="1">维护图片</option>
  255. <option value="2">新增新闻</option>
  256. </select>
  257. <br/><br/><input type="button" value="选中第二项" onclick="selectSecondItem2()" style="width:105px;"/>
  258. <input type="button" value="追加一项" onclick="appendItem2()" style="width:105px;"/>
  259. <input type="button" value="移除选中项" onclick="removeItem2()" style="width:105px;"/>
  260. </fieldset>
  261. <div class="height_15"></div>
  262. <fieldset>
  263. <legend>13、重置下拉框值</legend>
  264. <form id="form-14">
  265. <table class="tableStyle" formMode="transparent" style="width:400px;">
  266. <tr>
  267. <td>传统表单元素:</td>
  268. <td><input type="text"/></td>
  269. </tr>
  270. <tr>
  271. <td>下拉框1:</td>
  272. <td><select prompt="请选择" data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}' ></select></td>
  273. </tr>
  274. <tr>
  275. <td>下拉框2:</td>
  276. <td><select prompt="请选择" data='{"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]}' selectedValue="2"></select></td>
  277. </tr>
  278. <tr>
  279. <td colspan="2">
  280. <input type="button" value="提交"/>
  281. <input type="button" value="重置" onclick="resetForm()"/>
  282. </td>
  283. </tr>
  284. </table>
  285. </form>
  286. </fieldset>
  287. <div class="height_15"></div>
  288. <fieldset>
  289. <legend>14、不同表单元素横向排列</legend>
  290. 由于下拉框设置了float:left属性,如果直接将不同的元素横向排列,则会出现如下效果:<br/><br/>
  291. 姓名:
  292. <input type="text"/>
  293. 性别:
  294. <select>
  295. <option value="">请选择</option>
  296. </select>
  297. <input type="button" value="提交"/><br/><br/><br/><br/>
  298. 这时应该使用table来布局,每个元素放在一个td里面。效果如下:<br/><br/>
  299. <table>
  300. <tr>
  301. <td>姓名:</td>
  302. <td><input type="text"/></td>
  303. <td>性别:</td>
  304. <td>
  305. <select>
  306. <option value="">请选择</option>
  307. </select>
  308. </td>
  309. <td><input type="button" value="提交"/></td>
  310. </tr>
  311. </table>
  312. </fieldset>
  313. <div class="height_15"></div>
  314. <fieldset>
  315. <legend>15、获得选中节点自定义属性</legend>
  316. <select id="sel-16" prompt="请选择" data='{"list":[{"value":"1","key":"员工1","myFlag":"员工1-自定义属性"},{"value":"2","key":"员工2","myFlag":"员工2-自定义属性"}]}' ></select>
  317. </fieldset>
  318. <div class="height_15"></div>
  319. <fieldset>
  320. <legend>16、数据无前缀</legend>
  321. <select prompt="请选择员工" data='[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]'></select>
  322. </fieldset>
  323. <div class="height_15"></div>
  324. <fieldset>
  325. <legend>17、浏览器原始下拉框</legend>
  326. <select id="sel-15" keepDefaultStyle="true">
  327. <option value="">请选择功能</option>
  328. <option value="0">新增图片</option>
  329. <option value="1">维护图片</option>
  330. <option value="2">新增新闻</option>
  331. </select>
  332. </fieldset>
  333. <div class="height_15"></div>
  334. </div>
  335. <script type="text/javascript">
  336. //动态设置data
  337. function initComplete(){
  338. var selData={"list":[{"value":"1","key":"员工1"},{"value":"2","key":"员工2"}]};
  339. //赋给data
  340. $("#sel-1-2").data("data",selData)
  341. //刷新下拉框
  342. $("#sel-1-2").render();
  343. //获取json数据
  344. /*
  345. $.post("../../userAction.do?method=getUsersOfListFormation",{"userinfor.organization.orgId":"13"},function(result){
  346. //赋给data
  347. $("#sel-1-3").data("data",result)
  348. //刷新下拉框
  349. $("#sel-1-3").render();
  350. },"json");
  351. */
  352. //绑定change事件
  353. $("#sel-4").bind("change",function(){
  354. if(!$(this).attr("relValue")){
  355. top.Dialog.alert("没有选择节点");
  356. }else{
  357. top.Dialog.alert("选中节点文本:"+$(this).attr("relText")+"<br/>选中节点值:"+$(this).attr("relValue"));
  358. }
  359. })
  360. //"市"下拉框加载数据完成后触发的操作
  361. $("#sel-9-5").bind("ajaxInit",function(){
  362. $("#sel-9-6").render();
  363. });
  364. $("#sel-9-7").bind("change",function(){
  365. $("#sel-9-8").render();
  366. });
  367. $("#sel-9-10").bind("ajaxInit",function(){
  368. $("#sel-9-11").render();
  369. });
  370. $("#sel-9-13").bind("ajaxInit",function(){
  371. $("#sel-9-14").render();
  372. });
  373. //数据自定义属性
  374. $("#sel-16").bind("change",function(){
  375. if(!$(this).attr("relValue")){
  376. top.Dialog.alert("没有选择节点");
  377. }else{
  378. var node=$(this).data("selectedNode");
  379. top.Dialog.alert(node.myFlag);
  380. }
  381. })
  382. }
  383. //获取选中项
  384. function getSelectedItem(){
  385. var value = $("#sel-1-1").val();
  386. if(value){
  387. value += "(" + $("#sel-1-1").attr("relText") +")";
  388. }else{
  389. value = "无";
  390. }
  391. top.Dialog.alert(value);
  392. }
  393. //设为不可用
  394. function disableSelect(){
  395. $("#sel-3").attr("disabled",true);
  396. $("#sel-3").render();
  397. }
  398. //设为可用
  399. function enableSelect(){
  400. $("#sel-3").attr("disabled",false);
  401. $("#sel-3").render();
  402. }
  403. //onchange方法
  404. function onchangeHandler(obj){
  405. top.Dialog.alert("您选择了:" + $(obj).val());
  406. }
  407. //获取"可编辑"下拉项的值
  408. function getEditableValue(){
  409. var text = $("#sel-7").attr("editValue");
  410. if(!text){
  411. text = $("#sel-7").attr("prompt");
  412. }
  413. top.Dialog.alert(text);
  414. }
  415. //动态生成下拉框
  416. function dynamicSelectbox1(){
  417. /*
  418. var $selbox = $('<select prompt="请选择公司"></select>');
  419. $selbox.attr("url","../../organizationAction.do?method=getDepartments&parentid=0");
  420. //将下拉框加到按钮的后面
  421. $("#testBtn").after($selbox);
  422. $("#testBtn").after("<br/>");
  423. //渲染下拉框
  424. $selbox.render();
  425. */
  426. }
  427. //动态生成下拉框
  428. function dynamicSelectbox2(){
  429. //获取json数据
  430. /*
  431. $.post("../../organizationAction.do?method=getDepartments",{"parentid":"2"},function(result){
  432. var $selbox = $('<select prompt="请选择部门"></select>');
  433. //赋给data属性
  434. $selbox.data("data",result);
  435. //将下拉框加到按钮的后面
  436. $("#testBtn2").after($selbox);
  437. $("#testBtn2").after("<br/>");
  438. //渲染下拉框
  439. $selbox.render();
  440. },"json");
  441. */
  442. }
  443. //动态生成下拉框
  444. function dynamicSelectbox3(){
  445. var $selbox = $('<select><option value="0">请选择功能</option><option value="1" selected="selected">新增图片</option><option value="2">维护图片</option></select>');
  446. $("#testBtn3").after($selbox); //将下拉框加到按钮的后面
  447. $("#testBtn3").after("<br/>");
  448. $selbox.render(); //渲染下拉框
  449. }
  450. //json数据模式选择
  451. function selectSecondItem1(){
  452. $("#sel-12-1").setValue("1");
  453. }
  454. //json数据模式追加一项
  455. function appendItem1(){
  456. $("#sel-12-1").addItem({key: "新增项", value: "100"});
  457. $("#sel-12-1").setValue("100");
  458. }
  459. //json数据模式移除选择项
  460. function removeItem1(){
  461. $("#sel-12-1").removeItem("2");
  462. $("#sel-12-1").setValue("1");
  463. }
  464. //本地模式选择第二项
  465. function selectSecondItem2(){
  466. $("#sel-12-2")[0].selectedIndex = 1;
  467. $("#sel-12-2").render();
  468. }
  469. //本地模式追加一项
  470. function appendItem2(){
  471. //使用[0]是为了将JQuery对象转化为HTML对象
  472. var sel = $("#sel-12-2")[0];
  473. var length = sel.options.length;
  474. sel.options[length] = new Option("新增项" + length, length);
  475. $("#sel-12-2").val(length);
  476. $("#sel-12-2").render();
  477. }
  478. //本地模式移除选择项
  479. function removeItem2(){
  480. var sel = $("#sel-12-2")[0];
  481. sel.remove(sel.selectedIndex);
  482. $("#sel-12-2").render();
  483. }
  484. //表单重置
  485. function resetForm(){
  486. $("#form-14")[0].reset();
  487. $("#form-14 select").resetValue();
  488. }
  489. </script>
  490. </body>
  491. </html>