onrow.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>镜像站@Layui table模块,监听行事件 - 在线演示</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=1632428048260" media="all">
  16. <link rel="stylesheet" href="/public/static/css/global.css" tppabs="http://res.layui.com/static/css/global.css?t=1632428048260-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="layui-this">
  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="../flow.html" tppabs="http://www.layui.com/demo/flow.html">
  192. 流加载
  193. </a>
  194. </dd>
  195. <dd class="">
  196. <a href="../util.html" tppabs="http://www.layui.com/demo/util.html">
  197. 工具模块
  198. </a>
  199. </dd>
  200. <dd class="">
  201. <a href="../code.html" tppabs="http://www.layui.com/demo/code.html">
  202. 文本行修饰
  203. </a>
  204. </dd>
  205. </dl>
  206. </li>
  207. <li class="layui-nav-item" style="height: 30px; text-align: center"></li>
  208. </ul>
  209. </div>
  210. </div>
  211. <style>
  212. body .site-demo-title,
  213. body .layui-layout-admin .site-demo{left: 360px}
  214. .layui-layout-admin .site-demo-body{top: 107px;}
  215. body .site-demo-code{left: 160px;}
  216. </style>
  217. <div class="layui-side layui-side-child">
  218. <div class="layui-side-scroll">
  219. <!-- 左侧子菜单 -->
  220. <ul class="layui-nav layui-nav-tree site-demo-table-nav">
  221. <li class="layui-nav-item ">
  222. <a class="layui-nav-title" class="layui-nav-title" href="../table.html" tppabs="http://www.layui.com/demo/table.html">简单数据表格</a>
  223. </li>
  224. <li class="layui-nav-item ">
  225. <a class="layui-nav-title" href="auto.html" tppabs="http://www.layui.com/demo/table/auto.html">列宽自动分配<span class="layui-badge-dot"></span></a>
  226. </li>
  227. <li class="layui-nav-item ">
  228. <a class="layui-nav-title" href="data.html" tppabs="http://www.layui.com/demo/table/data.html">赋值已知数据</a>
  229. </li>
  230. <li class="layui-nav-item ">
  231. <a class="layui-nav-title" href="static.html" tppabs="http://www.layui.com/demo/table/static.html">转化静态表格</a>
  232. </li>
  233. <hr>
  234. <li class="layui-nav-item ">
  235. <a class="layui-nav-title" href="page.html" tppabs="http://www.layui.com/demo/table/page.html">开启分页</a>
  236. </li>
  237. <li class="layui-nav-item ">
  238. <a class="layui-nav-title" href="resetPage.html" tppabs="http://www.layui.com/demo/table/resetPage.html">自定义分页</a>
  239. </li>
  240. <li class="layui-nav-item ">
  241. <a class="layui-nav-title" href="toolbar.html" tppabs="http://www.layui.com/demo/table/toolbar.html">开启头部工具栏<span class="layui-badge-dot"></span></a>
  242. </li>
  243. <li class="layui-nav-item ">
  244. <a class="layui-nav-title" href="totalRow.html" tppabs="http://www.layui.com/demo/table/totalRow.html">开启合计行<span class="layui-badge-dot"></span></a>
  245. </li>
  246. <li class="layui-nav-item ">
  247. <a class="layui-nav-title" href="checkbox.html" tppabs="http://www.layui.com/demo/table/checkbox.html">开启复选框</a>
  248. </li>
  249. <li class="layui-nav-item ">
  250. <a class="layui-nav-title" href="radio.html" tppabs="http://www.layui.com/demo/table/radio.html">开启单选框<span class="layui-badge-dot"></span></a>
  251. </li>
  252. <li class="layui-nav-item ">
  253. <a class="layui-nav-title" href="cellEdit.html" tppabs="http://www.layui.com/demo/table/cellEdit.html">开启单元格编辑</a>
  254. </li>
  255. <hr>
  256. <li class="layui-nav-item ">
  257. <a class="layui-nav-title" href="form.html" tppabs="http://www.layui.com/demo/table/form.html">加入表单元素</a>
  258. </li>
  259. <li class="layui-nav-item ">
  260. <a class="layui-nav-title" href="style.html" tppabs="http://www.layui.com/demo/table/style.html">设置单元格样式</a>
  261. </li>
  262. <li class="layui-nav-item ">
  263. <a class="layui-nav-title" href="fixed.html" tppabs="http://www.layui.com/demo/table/fixed.html">固定列</a>
  264. </li>
  265. <hr>
  266. <li class="layui-nav-item ">
  267. <a class="layui-nav-title" href="operate.html" tppabs="http://www.layui.com/demo/table/operate.html">数据操作</a>
  268. </li>
  269. <li class="layui-nav-item ">
  270. <a class="layui-nav-title" href="parseData.html" tppabs="http://www.layui.com/demo/table/parseData.html">解析任意数据格式<span class="layui-badge-dot"></span></a>
  271. </li>
  272. <li class="layui-nav-item layui-this">
  273. <a class="layui-nav-title" href="onrow.html" tppabs="http://www.layui.com/demo/table/onrow.html">行事件<span class="layui-badge-dot"></span></a>
  274. </li>
  275. <li class="layui-nav-item ">
  276. <a class="layui-nav-title" href="reload.html" tppabs="http://www.layui.com/demo/table/reload.html">数据表格的重载</a>
  277. </li>
  278. <hr>
  279. <li class="layui-nav-item ">
  280. <a class="layui-nav-title" href="height.html" tppabs="http://www.layui.com/demo/table/height.html">高度最大化适应</a>
  281. </li>
  282. <li class="layui-nav-item ">
  283. <a class="layui-nav-title" href="initSort.html" tppabs="http://www.layui.com/demo/table/initSort.html">设置初始排序</a>
  284. </li>
  285. <li class="layui-nav-item ">
  286. <a class="layui-nav-title" href="cellEvent.html" tppabs="http://www.layui.com/demo/table/cellEvent.html">单元格事件</a>
  287. </li>
  288. <li class="layui-nav-item ">
  289. <a class="layui-nav-title" href="thead.html" tppabs="http://www.layui.com/demo/table/thead.html">复杂表头</a>
  290. </li>
  291. <hr>
  292. <li class="layui-nav-item">
  293. <a class="layui-nav-title" href="../../doc/modules/table.html" tppabs="http://www.layui.com/doc/modules/table.html" target="_blank">更多用法见文档</a>
  294. </li>
  295. </ul>
  296. </div>
  297. </div>
  298. <div class="layui-tab layui-tab-brief site-demo-table" lay-filter="demoTitle">
  299. <ul class="layui-tab-title site-demo-title">
  300. <li class="layui-this">预览</li>
  301. <li>查看代码</li>
  302. <li>帮助</li>
  303. </ul>
  304. <div class="layui-body layui-tab-content site-demo site-demo-body">
  305. <div class="layui-tab-item layui-show">
  306. <div class="layui-main">
  307. <div id="LAY_preview">
  308. <table class="layui-hide" id="test" lay-filter="test"></table>
  309. <script type="text/html" id="toolbarDemo">
  310. <div class="layui-btn-container">
  311. <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
  312. <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
  313. <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
  314. </div>
  315. </script>
  316. </div>
  317. <blockquote class="layui-elem-quote" style="margin-top: 30px;">
  318. 更多我们未能呈现的示例,还有待您在阅读文档、以及不断使用的过程,去深入挖掘。
  319. </blockquote>
  320. <div style="margin: 15px 0 100px; padding-bottom: 100px;">
  321. </div>
  322. </div>
  323. </div>
  324. <div class="layui-tab-item">
  325. <textarea class="layui-border-box site-demo-text site-demo-code" id="LAY_democode" spellcheck="false" readonly>
  326. <!DOCTYPE html>
  327. <html>
  328. <head>
  329. <meta charset="utf-8">
  330. <title>镜像站@Layui</title>
  331. <meta name="renderer" content="webkit">
  332. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  333. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  334. <link rel="stylesheet" href="/public/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css" media="all">
  335. <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
  336. </head>
  337. </textarea>
  338. </div>
  339. <div class="layui-tab-item">
  340. <div class="layui-main">
  341. <p></p>
  342. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  343. <legend>相关</legend>
  344. </fieldset>
  345. <a class="layui-btn layui-btn-normal" href="../../doc/modules/table.html" tppabs="http://www.layui.com/doc/modules/table.html" target="_blank">表格模块文档</a>
  346. </div>
  347. </div>
  348. </div>
  349. </div>
  350. <div class="layui-footer footer footer-demo">
  351. <p>
  352. Copyright &copy; 2021 <a href="../../index.html" tppabs="http://www.layui.com/">「本站仅为 layui 文档保留的镜像站点,与官方无关」</a> MIT Licensed</p>
  353. <p>
  354. <a href="../../about/disclaimer.html" tppabs="http://www.layui.com/about/disclaimer.html" target="_blank">免责声明</a>
  355. <a href="../../about/relatedlinks.html" tppabs="http://www.layui.com/about/relatedlinks.html" target="_blank">友链</a>
  356. <a href="javascript:;" site-event="weixinmp">公众号</a>
  357. </p>
  358. <div class="site-union">
  359. <p class="site-union-desc">
  360. <span>
  361. </span>
  362. </p>
  363. </div>
  364. </div>
  365. <script>
  366. window.global = {
  367. pageType: 'demo'
  368. ,preview: function(){
  369. var preview = document.getElementById('LAY_preview');
  370. return preview ? preview.innerHTML : '';
  371. }()
  372. };
  373. </script>
  374. <div class="site-tree-mobile layui-hide">
  375. <i class="layui-icon layui-icon-spread-left"></i>
  376. </div>
  377. <div class="site-mobile-shade"></div>
  378. <script src="/public/layui/dist/layui.js" tppabs="http://res.layui.com/layui/dist/layui.js?t=1632428048260" charset="utf-8"></script>
  379. <script>
  380. layui.config({
  381. base: '/public/static/lay/modules/layui/'
  382. ,version: '1632428048260'
  383. }).use('global');
  384. </script>
  385. </div>
  386. <div id="LAY_democodejs">
  387. <script>
  388. layui.use('table', function(){
  389. var table = layui.table;
  390. table.render({
  391. elem: '#test'
  392. ,url:'../../test/table/demo1.json.js'/*tpa=http://www.layui.com/test/table/demo1.json*/
  393. ,cols: [[
  394. {field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
  395. ,{field:'username', title:'用户名', width:120}
  396. ,{field:'email', title:'邮箱', width:150, templet: function(res){
  397. return '<em>'+ res.email +'</em>'
  398. }}
  399. ,{field:'sex', title:'性别', width:80, sort: true}
  400. ,{field:'city', title:'城市', width:100}
  401. ,{field:'sign', title:'签名'}
  402. ,{field:'experience', title:'积分', width:80, sort: true}
  403. ,{field:'ip', title:'IP', width:120}
  404. ,{field:'logins', title:'登入次数', width:100, sort: true}
  405. ,{field:'joinTime', title:'加入时间', width:120}
  406. ]]
  407. ,page: true
  408. });
  409. //监听行单击事件(双击事件为:rowDouble)
  410. table.on('row(test)', function(obj){
  411. var data = obj.data;
  412. layer.alert(JSON.stringify(data), {
  413. title: '当前行数据:'
  414. });
  415. //标注选中样式
  416. obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
  417. });
  418. });
  419. </script>
  420. </div>
  421. </body>
  422. </html>