80cf7230f21aeaffbbeb1cdbea3f2727193ee136.svn-base 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. <!-- 自动完成框start -->
  15. <script type="text/javascript" src="../../libs/js/form/autoComplete.js"></script>
  16. <!-- 自动完成框end -->
  17. </head>
  18. <body>
  19. <div class="box1" panelWidth="800">
  20. <fieldset>
  21. <legend>1、通过url获取数据源</legend>
  22. <div class="red">此示例由后台支持</div>
  23. <p>提示:输入“红烧肉”,“水煮肉片”,“酸辣汤”,“家常豆腐”,“鱼香茄子”,“干煸豆角”的第一个字测试。</p>
  24. <input type="text" class="autoComplete" url="../../autoComplateAction.do?method=getListByWord"/>
  25. <p>匹配参数名默认为"q";获取的JSON数据的数据名默认为"list",可使用dataRoot属性改变</p>
  26. </fieldset>
  27. <div class="height_15"></div>
  28. <fieldset>
  29. <legend>2、通过url+参数获取数据源</legend>
  30. <div class="red">此示例由后台支持</div>
  31. <p>输入邮箱地址。</p>
  32. <input type="text" class="autoComplete" url="../../autoComplateAction.do?method=getListByEmail" params='{"userAge": "26", "userSex": "1"}' matchName="userName"/>
  33. <p>这里除了传递了参数,还自定义匹配参数名为"userName"。然后根据输入的值返回自定义的结果,实现了一个邮箱提示框。</p>
  34. </fieldset>
  35. <div class="height_15"></div>
  36. <fieldset>
  37. <legend>3、使用data(本地数据)</legend>
  38. <p>可分别输入”红烧肉“,“牛肉汤”,“酸梅汤”第一个字测试。</p>
  39. <input type="text" id="input-3" class="autoComplete"/>
  40. </fieldset>
  41. <div class="height_15"></div>
  42. <fieldset>
  43. <legend>4、限定匹配字数和现实条数</legend>
  44. <div class="red">此示例由后台支持</div>
  45. <p>输入“HS”或“QZ”测试(不区分大小写)。</p>
  46. <input type="text" class="autoComplete" url="../../autoComplateAction.do?method=getListByChar" minChars="2" limit="50"/>
  47. <p>此示例中,输入2个字符后才开始匹配,且最多显示50条结果。以免数据量太大引起渲染的问题。</p>
  48. </fieldset>
  49. <div class="height_15"></div>
  50. <fieldset>
  51. <legend>5、通过拼音首字母获取匹配列表</legend>
  52. <div class="red">此示例由后台支持</div>
  53. <p>可分别输入”S“,“HS”,“SL”,“SZ”测试(不区分大小写)。</p>
  54. <input type="text" class="autoComplete" url="../../autoComplateAction.do?method=getListByChar" />
  55. </fieldset>
  56. <div class="height_15"></div>
  57. <fieldset>
  58. <legend>6、自定义尺寸</legend>
  59. <div class="red">此示例由后台支持</div>
  60. <p>输入邮箱地址。</p>
  61. <input type="text" class="autoComplete" url="../../autoComplateAction.do?method=getListByEmail" matchName="userName" inputWidth="250" boxWidth="250"/>
  62. </fieldset>
  63. <div class="height_15"></div>
  64. <fieldset>
  65. <legend>7、多列提示</legend>
  66. <div class="red">此示例由后台支持</div>
  67. <p>输入“红”测试。</p>
  68. <input type="text" class="autoComplete" url="../../autoComplateAction.do?method=getListByMutiCols" boxWidth="250" colMulti="true" colIdx="0"/>
  69. <p>设置多列并指定点击后选中的是哪一列的数据</p>
  70. </fieldset>
  71. <div class="height_15"></div>
  72. <fieldset>
  73. <legend>8、禁用/启用</legend>
  74. <div class="red">此示例由后台支持</div>
  75. <p>可分别输入”S“,“HS”,“SL”,“SZ”测试(不区分大小写)。</p>
  76. <input type="text" class="autoComplete" url="../../autoComplateAction.do?method=getListByChar" disabled="true" id="input-8"/>
  77. <input type="button" value="启用" onclick="enable()" style="width:105px;"/>
  78. <input type="button" value="禁用" onclick="disable()" style="width:105px;"/>
  79. </fieldset>
  80. <div class="height_15"></div>
  81. <fieldset>
  82. <legend>9、动态创建</legend>
  83. <div class="red">此示例由后台支持</div>
  84. <input type="button" value="点击生成" id="testBtn" onclick="dynamic()" style="width:150px;"/>
  85. </fieldset>
  86. <fieldset>
  87. <legend>10、手动渲染</legend>
  88. <div class="red">此示例由后台支持</div>
  89. <p>可分别输入”S“,“BJ”,“SH”,“SZ”测试(不区分大小写)。</p>
  90. <input type="text" id="input-10" class="autoCompleteIcon"/> <label id="label0"></label>
  91. <p>手动渲染可以监听事件。<br/>
  92. 可监听的事件有:onBeforeListLoad(开始请求后台数据时触发)、onListLoaded(数据列表生成后触发)、onItemSelected(选择条目时触发)</p>
  93. </fieldset>
  94. <div class="height_15"></div>
  95. <fieldset>
  96. <legend>11、综合示例</legend>
  97. <div class="red">此示例由后台支持</div>
  98. 仿网易邮箱的邮件查询。点击按钮在新窗口查看<br/>
  99. <input type="button" value="打开" onclick='top.Dialog.open({URL:"../../sample_html/form/autocomplete-content.html",Title:"示例",Width:"100",Height:"100"});'/>
  100. </fieldset>
  101. <div class="height_15"></div>
  102. </div>
  103. <script type="text/javascript">
  104. function initComplete(){
  105. //动态设置data
  106. var myData={"list" : ["红烧肉","红烧排骨","红烧鸡翅","汉堡","牛肉汤","牛肉酱","牛肉炖土豆","牛奶炖蛋","酸奶蛋糕","酸梅汤"]};
  107. $('#input-3').data("data",myData);
  108. $('#input-3').render();
  109. //手动渲染
  110. $('#input-10').AutoComplete({
  111. url: '../../autoComplateAction.do?method=getListByChar',
  112. onBeforeListLoad: function(){
  113. top.Dialog.alert("请求数据...<br/>对于重复的请求,会使用缓存中的查询结果,不再去服务器查询。");
  114. },
  115. onItemSelected: function(item){
  116. top.Dialog.alert("选择了:" + item.text());
  117. },
  118. onListLoaded: function(list){
  119. $("#label0").html("符合项的个数:" + list.find('li').size());
  120. }
  121. });
  122. }
  123. //设为不可用
  124. function disable(){
  125. $("#input-8").attr("disabled",true);
  126. }
  127. //设为可用
  128. function enable(){
  129. $("#input-8").attr("disabled",false);
  130. }
  131. //动态生成
  132. function dynamic(){
  133. var $auto = $('<input type="text" class="autoComplete"/>');
  134. $auto.attr("url","../../autoComplateAction.do?method=getListByChar");
  135. $("#testBtn").after($auto);
  136. $("#testBtn").after($("<br/>"));
  137. //渲染
  138. $auto.render();
  139. }
  140. </script>
  141. </body>
  142. </html>