网页技术交流
 
发新帖
楼主: 零五零八
查看: 722|回复: 0

[使用教程] AmazeUI 按钮交互的实现示例

[复制链接]
零五零八 发表于 2020-11-10 10:23:05 | 显示全部楼层
本文主要介绍了AmazeUI 按钮交互的实现示例,分享给大家,具体如下:


  1. <!doctype html>
  2. <html class="no-js">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="description" content="">
  7. <meta name="keywords" content="">
  8. <meta name="viewport" content="width=device-width, initial-scale=1">
  9. <title>按钮交互</title>
  10. <meta name="renderer" content="webkit">
  11. <meta http-equiv="Cache-Control" content="no-siteapp"/>
  12. <link rel="icon" type="image/png" href="assets/i/favicon.png">
  13. <meta name="mobile-web-app-capable" content="yes">
  14. <link rel="icon" sizes="192x192" href="assets/i/app-icon72x72@2x.png">
  15. <meta name="apple-mobile-web-app-capable" content="yes">
  16. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  17. <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
  18. <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
  19. <meta name="msapplication-TileImage" content="assets/i/app-icon72x72@2x.png">
  20. <meta name="msapplication-TileColor" content="#0e90d2">
  21. <link rel="stylesheet" href="assets/css/amazeui.min.css">
  22. <!--[if (gte IE 9)|!(IE)]><!-->
  23. <script src="assets/js/jquery.min.js"></script>
  24. <!--<![endif]-->
  25. <!--[if lte IE 8 ]>
  26. <script src="assets/ie8/jquery.min.js"></script>
  27. <script src="assets/ie8/modernizr.js"></script>
  28. <script src="assets/js/amazeui.ie8polyfill.min.js"></script>
  29. <![endif]-->
  30. <script src="assets/js/amazeui.min.js"></script>
  31. </head>
  32. <body style="margin: 50px;">
  33. <!--按钮 loading 状态-->
  34. <button type="button" class="am-btn am-btn-primary btn-loading-example">Submit - Button</button>
  35. <input type="button" class="am-btn am-btn-primary btn-loading-example" value="Submit - Input" />
  36. <script>
  37. $('.btn-loading-example').click(function () {
  38. var $btn = $(this)
  39. $btn.button('loading');
  40. setTimeout(function(){
  41.   $btn.button('reset');
  42. }, 5000);
  43. });
  44. </script>
  45. <!--自定义选项-->
  46. <button type="button" class="am-btn am-btn-primary btn-loading-example" data-am-loading="{spinner: 'circle-o-notch', loadingText: '加载中...', resetText: '加载过了'}">按钮 - button 元素</button>
  47. <input type="button" class="am-btn am-btn-secondary btn-loading-example" value="按钮 - input 元素" data-am-loading="{loadingText: '努力加载中...'}" />
  48. <script>
  49. $('.btn-loading-example').click(function () {
  50. var $btn = $(this)
  51. $btn.button('loading');
  52. setTimeout(function(){
  53.   $btn.button('reset');
  54. }, 5000);
  55. });
  56. </script>
  57. <!--单按钮状态切换-->
  58. <button id="doc-single-toggle" type="button" class="am-btn am-btn-primary" data-am-button>切换状态</button>
  59. <p>按钮状态:<span id="doc-single-toggle-status" class="am-text-danger">未激活</span></p>
  60. <script>
  61. $(function() {
  62. var $toggleButton = $('#doc-single-toggle');
  63. $toggleButton.on('click', function() {
  64.   setButtonStatus();
  65. });

  66. function setButtonStatus() {
  67.   var status = $toggleButton.hasClass('am-active') ? '未激活' : '激活';
  68.   $('#doc-single-toggle-status').text(status);
  69. }
  70. })
  71. </script>
  72. <!--复选框-->
  73. <div class="am-btn-group" data-am-button>
  74. <label class="am-btn am-btn-primary">
  75.   <input type="checkbox" name="doc-js-btn" value="苹果"> 苹果
  76. </label>
  77. <label class="am-btn am-btn-primary">
  78.   <input type="checkbox" name="doc-js-btn" value="橘子"> 橘子
  79. </label>
  80. <label class="am-btn am-btn-primary">
  81.   <input type="checkbox" name="doc-js-btn" value="香蕉"> 香蕉
  82. </label>
  83. </div>
  84. <script>
  85. $(function() {
  86. var $cb = $('[name="doc-js-btn"]');
  87. $cb.on('change', function() {
  88.   var checked = [];
  89.   $cb.filter(':checked').each(function() {
  90.    checked.push(this.value);
  91.   });

  92.   console.log('复选框选中的是:', checked.join(' | '));
  93. });
  94. });
  95. </script>
  96. <!--单选框-->
  97. <div class="am-btn-group doc-js-btn-1" data-am-button>
  98. <label class="am-btn am-btn-primary">
  99.   <input type="radio" name="options" value="选项 1" id="option1"> 选项 1
  100. </label>
  101. <label class="am-btn am-btn-primary">
  102.   <input type="radio" name="options" value="选项 2" id="option2"> 选项 2
  103. </label>
  104. <label class="am-btn am-btn-primary">
  105.   <input type="radio" name="options" value="选项 3" id="option3"> 选项 3
  106. </label>
  107. <label class="am-btn am-btn-primary am-disabled">
  108.   <input type="radio" name="options" value="选项 4" id="option4"> 选项 4
  109. </label>
  110. </div>
  111. <script>
  112. // 获取选中的值
  113. $(function() {
  114. var $radios = $('[name="options"]');
  115. $radios.on('change',function() {
  116.   console.log('单选框当前选中的是:', $radios.filter(':checked').val());
  117. });
  118. });
  119. </script>
  120. </body>
  121. </html>
复制代码


效果图:


1.png
快速回复 返回顶部 返回列表