util.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>镜像站@工具集 - 在线演示 - Layui</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <meta name="format-detection" content="telephone=no">
  12. <script>
  13. ;!function(){self!==parent&&(location.href="http://www.baidu.com/")}();
  14. </script>
  15. <link rel="stylesheet" href="/public/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css?t=1632428048355" media="all">
  16. <link rel="stylesheet" href="/public/static/css/global.css" tppabs="http://res.layui.com/static/css/global.css?t=1632428048355-19" media="all">
  17. </head>
  18. <body>
  19. <div class="layui-layout layui-layout-admin">
  20. <div class="layui-header header header-demo" autumn>
  21. <div class="layui-fluid">
  22. <a class="logo" href="../index.html" tppabs="http://www.layui.com/">
  23. <img src="/public/static/images/layui/logo.png" tppabs="http://res.layui.com/static/images/layui/logo.png" alt="layui">
  24. </a>
  25. <div class="layui-form layui-hide-xs component" lay-filter="LAY-site-header-component"></div>
  26. <div class="layui-hide-xs site-notice"></div>
  27. <ul class="layui-nav" id="LAY_NAV_TOP">
  28. <li class="layui-nav-item ">
  29. <a href="../doc/index.html" tppabs="http://www.layui.com/doc/">文档</a>
  30. </li>
  31. <li class="layui-nav-item layui-this">
  32. <a href="index.html" tppabs="http://www.layui.com/demo/">示例</a>
  33. </li>
  34. <li class="layui-nav-item">
  35. <a href="javascript:;">
  36. <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>-->
  37. 周边
  38. </a>
  39. <dl class="layui-nav-child layui-nav-child-c">
  40. <dd class="layui-hide-sm layui-show-xs" lay-unselect>
  41. <a href="https://gitee.com/sentsin/layui/issues" target="_blank" rel="nofollow">问题反馈</a>
  42. <hr>
  43. </dd>
  44. <dd lay-unselect><a href="../alone.html" tppabs="http://www.layui.com/alone.html" target="_blank" lay-unselect>独立组件</a></dd>
  45. <dd lay-unselect><a href="../../fly.layui.com/extend/index.html" target="_blank">扩展组件</a></dd>
  46. </dl>
  47. </li>
  48. <li class="layui-nav-item layui-hide-xs">
  49. <a href="http://gitee.com/sentsin/layui/issues" target="_blank" rel="nofollow">反馈</a>
  50. </li>
  51. </ul>
  52. </div>
  53. </div>
  54. <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
  55. <!--[if lt IE 9]>
  56. <script src="../../other/html5shiv/r29/html5.min.js" tppabs="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  57. <script src="../../other/respond.js/1.4.2/respond.min.js" tppabs="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  58. <![endif]-->
  59. <div class="layui-side layui-bg-black">
  60. <div class="layui-side-scroll">
  61. <ul class="layui-nav layui-nav-tree site-demo-nav">
  62. <li class="layui-nav-item layui-nav-itemed">
  63. <a class="javascript:;" href="javascript:;">演示</a>
  64. <dl class="layui-nav-child">
  65. <dd>
  66. <a href="index.html" tppabs="http://www.layui.com/demo/">调试预览</a>
  67. </dd>
  68. </dl>
  69. </li>
  70. <li class="layui-nav-item layui-nav-itemed">
  71. <a class="javascript:;" href="javascript:;">布局</a>
  72. <dl class="layui-nav-child">
  73. <dd class="">
  74. <a href="grid.html" tppabs="http://www.layui.com/demo/grid.html">栅格</a>
  75. </dd>
  76. <dd class="">
  77. <a href="admin.html" tppabs="http://www.layui.com/demo/admin.html">框架</a>
  78. </dd>
  79. </dl>
  80. </li>
  81. <li class="layui-nav-item layui-nav-itemed">
  82. <a class="javascript:;" href="javascript:;">基本元素</a>
  83. <dl class="layui-nav-child">
  84. <dd class="">
  85. <a href="button.html" tppabs="http://www.layui.com/demo/button.html">按钮</a>
  86. </dd>
  87. <dd class="">
  88. <a href="form.html" tppabs="http://www.layui.com/demo/form.html">表单</a>
  89. </dd>
  90. <dd class="">
  91. <a href="nav.html" tppabs="http://www.layui.com/demo/nav.html">导航 / 面包屑</a>
  92. </dd>
  93. <dd class="">
  94. <a href="menu.html" tppabs="http://www.layui.com/demo/menu.html">基础菜单</a>
  95. </dd>
  96. <dd class="">
  97. <a href="tab.html" tppabs="http://www.layui.com/demo/tab.html">选项卡</a>
  98. </dd>
  99. <dd class="">
  100. <a href="progress.html" tppabs="http://www.layui.com/demo/progress.html">进度条</a>
  101. </dd>
  102. <dd class="">
  103. <a href="panel.html" tppabs="http://www.layui.com/demo/panel.html">面板</a>
  104. </dd>
  105. <dd class="">
  106. <a href="badge.html" tppabs="http://www.layui.com/demo/badge.html">徽章</a>
  107. </dd>
  108. <dd class="">
  109. <a href="timeline.html" tppabs="http://www.layui.com/demo/timeline.html">时间线</a>
  110. </dd>
  111. <dd class="">
  112. <a href="table-element.html" tppabs="http://www.layui.com/demo/table-element.html">静态表格</a>
  113. </dd>
  114. <dd class="">
  115. <a href="anim.html" tppabs="http://www.layui.com/demo/anim.html">动画</a>
  116. </dd>
  117. <dd class="">
  118. <a href="auxiliar.html" tppabs="http://www.layui.com/demo/auxiliar.html">辅助元素</a>
  119. </dd>
  120. </dl>
  121. </li>
  122. <li class="layui-nav-item layui-nav-itemed">
  123. <a class="javascript:;" href="javascript:;">组件示例</a>
  124. <dl class="layui-nav-child">
  125. <dd class="">
  126. <a href="layer.html" tppabs="http://www.layui.com/demo/layer.html">
  127. 弹出层
  128. </a>
  129. </dd>
  130. <dd class="">
  131. <a href="laydate.html" tppabs="http://www.layui.com/demo/laydate.html">
  132. 日期与时间选择
  133. </a>
  134. </dd>
  135. <dd class="">
  136. <a href="table.html" tppabs="http://www.layui.com/demo/table.html">
  137. 数据表格
  138. </a>
  139. </dd>
  140. <dd class="">
  141. <a href="laypage.html" tppabs="http://www.layui.com/demo/laypage.html">
  142. 分页
  143. </a>
  144. </dd>
  145. <dd class="">
  146. <a href="dropdown.html" tppabs="http://www.layui.com/demo/dropdown.html">
  147. 下拉菜单
  148. </a>
  149. </dd>
  150. <dd class="">
  151. <a href="upload.html" tppabs="http://www.layui.com/demo/upload.html">
  152. 文件上传
  153. </a>
  154. </dd>
  155. <dd class="">
  156. <a href="transfer.html" tppabs="http://www.layui.com/demo/transfer.html">
  157. 穿梭框
  158. </a>
  159. </dd>
  160. <dd class="">
  161. <a href="tree.html" tppabs="http://www.layui.com/demo/tree.html">
  162. 树形组件
  163. </a>
  164. </dd>
  165. <dd class="">
  166. <a href="colorpicker.html" tppabs="http://www.layui.com/demo/colorpicker.html">
  167. 颜色选择器
  168. </a>
  169. </dd>
  170. <dd class="">
  171. <a href="slider.html" tppabs="http://www.layui.com/demo/slider.html">
  172. 滑块
  173. </a>
  174. </dd>
  175. <dd class="">
  176. <a href="rate.html" tppabs="http://www.layui.com/demo/rate.html">
  177. 评分
  178. </a>
  179. </dd>
  180. <dd class="">
  181. <a href="carousel.html" tppabs="http://www.layui.com/demo/carousel.html">
  182. 轮播
  183. </a>
  184. </dd>
  185. <dd class="">
  186. <a href="laytpl.html" tppabs="http://www.layui.com/demo/laytpl.html">
  187. 模板引擎
  188. </a>
  189. </dd>
  190. <dd class="">
  191. <a href="layedit.html" tppabs="http://www.layui.com/demo/layedit.html">
  192. 富文本编辑器
  193. </a>
  194. </dd>
  195. <dd class="">
  196. <a href="flow.html" tppabs="http://www.layui.com/demo/flow.html">
  197. 流加载
  198. </a>
  199. </dd>
  200. <dd class="layui-this">
  201. <a href="util.html" tppabs="http://www.layui.com/demo/util.html">
  202. 工具模块
  203. </a>
  204. </dd>
  205. <dd class="">
  206. <a href="code.html" tppabs="http://www.layui.com/demo/code.html">
  207. 文本行修饰
  208. </a>
  209. </dd>
  210. </dl>
  211. </li>
  212. <li class="layui-nav-item" style="height: 30px; text-align: center"></li>
  213. </ul>
  214. </div>
  215. </div>
  216. <div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
  217. <ul class="layui-tab-title site-demo-title">
  218. <li class="layui-this">预览</li>
  219. <li>查看代码</li>
  220. <li>帮助</li>
  221. </ul>
  222. <div class="layui-body layui-tab-content site-demo site-demo-body">
  223. <div class="layui-tab-item layui-show">
  224. <div class="layui-main">
  225. <div id="LAY_preview">
  226. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  227. <legend>固定块</legend>
  228. </fieldset>
  229. <p>囖,就页面右下角的那个。</p>
  230. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  231. <legend>倒计时</legend>
  232. </fieldset>
  233. 请选择要计算的日期:
  234. <div class="layui-inline">
  235. <input type="text" class="layui-input" id="test1" value="2099-01-01 00:00:00">
  236. </div>
  237. <blockquote class="layui-elem-quote" style="margin-top: 10px;">
  238. <div id="test2"></div>
  239. </blockquote>
  240. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  241. <legend>某个时间在当前时间的多久前</legend>
  242. </fieldset>
  243. 请选择要计算的日期:
  244. <div class="layui-inline">
  245. <input type="text" class="layui-input" id="test3">
  246. </div>
  247. <span class="layui-word-aux" id="test4"></span>
  248. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  249. <legend>转换日期格式</legend>
  250. </fieldset>
  251. 请编辑格式:
  252. <div class="layui-inline">
  253. <input type="text" value="yyyy-MM-dd HH:mm:ss" class="layui-input" id="test5">
  254. </div>
  255. <span class="layui-word-aux" id="test6"></span>
  256. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  257. <legend>批量处理事件</legend>
  258. </fieldset>
  259. <div class="layui-btn-container">
  260. <button class="layui-btn" lay-active="e1">事件1</button>
  261. <button class="layui-btn" lay-active="e2">事件2</button>
  262. <button class="layui-btn" lay-active="e3">事件3</button>
  263. </div>
  264. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  265. <legend>XSS 过滤</legend>
  266. </fieldset>
  267. <div class="layui-form layui-inline" style="width: 300px;">
  268. <textarea class="layui-textarea" id="test7">
  269. <script>
  270. alert(0);
  271. </script>
  272. </textarea>
  273. </div>
  274. <div class="layui-btn-container" style="margin-top: 10px;">
  275. <button class="layui-btn" id="test8">执行过滤</button>
  276. </div>
  277. </div>
  278. <blockquote class="layui-elem-quote" style="margin-top: 30px;">
  279. 更多我们未能呈现的示例,还有待您在阅读文档、以及不断使用的过程,去深入挖掘。
  280. </blockquote>
  281. <div style="margin: 15px 0 100px; padding-bottom: 100px;">
  282. </div>
  283. </div>
  284. </div>
  285. <div class="layui-tab-item">
  286. <textarea class="layui-border-box site-demo-text site-demo-code" id="LAY_democode" spellcheck="false" readonly>
  287. <!DOCTYPE html>
  288. <html>
  289. <head>
  290. <meta charset="utf-8">
  291. <title>镜像站@Layui</title>
  292. <meta name="renderer" content="webkit">
  293. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  294. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  295. <link rel="stylesheet" href="/public/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css" media="all">
  296. <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
  297. </head>
  298. </textarea>
  299. </div>
  300. <div class="layui-tab-item">
  301. <div class="layui-main">
  302. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  303. <legend>相关</legend>
  304. </fieldset>
  305. <a class="layui-btn layui-btn-normal" href="../doc/modules/util.html" tppabs="http://www.layui.com/doc/modules/util.html" target="_blank">util 文档</a>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. <div class="layui-footer footer footer-demo">
  311. <p>
  312. Copyright &copy; 2021 <a href="../index.html" tppabs="http://www.layui.com/">「本站仅为 layui 文档保留的镜像站点,与官方无关」</a> MIT Licensed</p>
  313. <p>
  314. <a href="../about/disclaimer.html" tppabs="http://www.layui.com/about/disclaimer.html" target="_blank">免责声明</a>
  315. <a href="../about/relatedlinks.html" tppabs="http://www.layui.com/about/relatedlinks.html" target="_blank">友链</a>
  316. <a href="javascript:;" site-event="weixinmp">公众号</a>
  317. </p>
  318. <div class="site-union">
  319. <p class="site-union-desc">
  320. <span>
  321. </span>
  322. </p>
  323. </div>
  324. </div>
  325. <script>
  326. window.global = {
  327. pageType: 'demo'
  328. ,preview: function(){
  329. var preview = document.getElementById('LAY_preview');
  330. return preview ? preview.innerHTML : '';
  331. }()
  332. };
  333. </script>
  334. <div class="site-tree-mobile layui-hide">
  335. <i class="layui-icon layui-icon-spread-left"></i>
  336. </div>
  337. <div class="site-mobile-shade"></div>
  338. <script src="/public/layui/dist/layui.js" tppabs="http://res.layui.com/layui/dist/layui.js?t=1632428048355" charset="utf-8"></script>
  339. <script>
  340. layui.config({
  341. base: '/public/static/lay/modules/layui/'
  342. ,version: '1632428048355'
  343. }).use('global');
  344. </script>
  345. </div>
  346. <div id="LAY_democodejs">
  347. <script>
  348. layui.use(['util', 'laydate', 'layer'], function(){
  349. var util = layui.util
  350. ,laydate = layui.laydate
  351. ,$ = layui.$
  352. ,layer = layui.layer;
  353. //固定块
  354. util.fixbar({
  355. bar1: true
  356. ,bar2: true
  357. ,css: {right: 50, bottom: 100}
  358. ,bgcolor: '#393D49'
  359. ,click: function(type){
  360. if(type === 'bar1'){
  361. layer.msg('icon 是可以随便换的')
  362. } else if(type === 'bar2') {
  363. layer.msg('两个 bar 都可以设定是否开启')
  364. }
  365. }
  366. });
  367. //倒计时
  368. var thisTimer, setCountdown = function(y, M, d, H, m, s){
  369. var endTime = new Date(y, M||0, d||1, H||0, m||0, s||0) //结束日期
  370. ,serverTime = new Date(); //假设为当前服务器时间,这里采用的是本地时间,实际使用一般是取服务端的
  371. clearTimeout(thisTimer);
  372. util.countdown(endTime, serverTime, function(date, serverTime, timer){
  373. var str = date[0] + '天' + date[1] + '时' + date[2] + '分' + date[3] + '秒';
  374. lay('#test2').html(str);
  375. thisTimer = timer;
  376. });
  377. };
  378. setCountdown(2099,1,1);
  379. laydate.render({
  380. elem: '#test1'
  381. ,type: 'datetime'
  382. ,done: function(value, date){
  383. setCountdown(date.year, date.month - 1, date.date, date.hours, date.minutes, date.seconds);
  384. }
  385. });
  386. //某个时间在当前时间的多久前
  387. var setTimeAgo = function(y, M, d, H, m, s){
  388. var str = util.timeAgo(new Date(y, M||0, d||1, H||0, m||0, s||0));
  389. lay('#test4').html(str);
  390. };
  391. laydate.render({
  392. elem: '#test3'
  393. ,type: 'datetime'
  394. ,done: function(value, date){
  395. setTimeAgo(date.year, date.month - 1, date.date, date.hours, date.minutes, date.seconds);
  396. }
  397. });
  398. //转换日期格式
  399. var toDateString = function(format){
  400. var dateString = util.toDateString(new Date(), format); //执行转换日期格式的方法
  401. $('#test6').html(dateString);
  402. };
  403. toDateString($('#test5').val());
  404. //监听输入框事件
  405. $('#test5').on('keyup', function(){
  406. toDateString(this.value);
  407. });
  408. //处理属性 为 lay-active 的所有元素事件
  409. util.event('lay-active', {
  410. e1: function(){
  411. layer.msg('触发了事件1');
  412. }
  413. ,e2: function(){
  414. layer.msg('触发了事件2');
  415. }
  416. ,e3: function(){
  417. layer.msg('触发了事件3');
  418. }
  419. });
  420. //XSS 过滤
  421. $('#test8').on('click', function(){ //监听按钮事件
  422. var str = util.escape($('#test7').val()); //执行 xss 过滤方法
  423. alert(str);
  424. });
  425. });
  426. </script>
  427. </div>
  428. </body>
  429. </html>