amazeui学习笔记--js插件(UI增强2)--按钮交互Button

一、总结

1、按钮loading状态

<button type="button" class="am-btn am-btn-primary btn-loading-example">Submit - Button</button>
<input type="button" class="am-btn am-btn-primary btn-loading-example" value="Submit - Input" /> $('.btn-loading-example').click(function () {
var $btn = $(this)
$btn.button('loading');
setTimeout(function(){
$btn.button('reset');
}, 5000);
});

2、按钮loading状态自定义选项(功能)

可以在元素上添加 data-am-loading 来设置选项:

  • spinner 加载动画图标,适用于支持 CSS3 动画、非 input 元素,写图标名称即可;
  • loadingText 加载时显示的文字, 默认为 loading
  • resetText 重置以后的显示的文字,默认为原来的内容。
<button type="button" class="am-btn am-btn-primary btn-loading-example" data-am-loading="{spinner: 'circle-o-notch', loadingText: '加载中...', resetText: '加载过了'}">按钮 - button 元素</button>

<input type="button" class="am-btn am-btn-secondary btn-loading-example" value="按钮 - input 元素" data-am-loading="{loadingText: '努力加载中...'}" />

$('.btn-loading-example').click(function () {
var $btn = $(this)
$btn.button('loading');
setTimeout(function(){
$btn.button('reset');
}, 5000);
});

3、单按钮状态切换

 <button id="doc-single-toggle" type="button" class="am-btn am-btn-primary" data-am-button>切换状态</button>

 <p>按钮状态:<span id="doc-single-toggle-status" class="am-text-danger">未激活</span></p>

 <script>
$(function() {
var $toggleButton = $('#doc-single-toggle');
$toggleButton.on('click', function() {
setButtonStatus();
}); function setButtonStatus() {
var status = $toggleButton.hasClass('am-active') ? '未激活' : '激活';
$('#doc-single-toggle-status').text(status);
}
})
</script>

4、默认选中状态:  <label> 上添加 am-active 类名    <input> 上添加 checked 属性。

5、单选框:

 <div class="am-btn-group doc-js-btn-1" data-am-button>
<label class="am-btn am-btn-primary">
<input type="radio" name="options" value="选项 1" id="option1"> 选项 1
</label>
<label class="am-btn am-btn-primary">
<input type="radio" name="options" value="选项 2" id="option2"> 选项 2
</label>
<label class="am-btn am-btn-primary">
<input type="radio" name="options" value="选项 3" id="option3"> 选项 3
</label>
<label class="am-btn am-btn-primary am-disabled">
<input type="radio" name="options" value="选项 4" id="option4"> 选项 4
</label>
</div>
<script>
// 获取选中的值
$(function() {
var $radios = $('[name="options"]');
$radios.on('change',function() {
console.log('单选框当前选中的是:', $radios.filter(':checked').val());
});
});
</script>

6、复选框

<div class="am-btn-group" data-am-button>
<label class="am-btn am-btn-primary">
<input type="checkbox" name="doc-js-btn" value="苹果"> 苹果
</label>
<label class="am-btn am-btn-primary">
<input type="checkbox" name="doc-js-btn" value="橘子"> 橘子
</label>
<label class="am-btn am-btn-primary">
<input type="checkbox" name="doc-js-btn" value="香蕉"> 香蕉
</label>
</div>
<script>
$(function() {
var $cb = $('[name="doc-js-btn"]');
$cb.on('change', function() {
var checked = [];
$cb.filter(':checked').each(function() {
checked.push(this.value);
}); console.log('复选框选中的是:', checked.join(' | '));
});
});
</script>

二、按钮交互Button

Button JS 交互


Button 及 Button group 与 JS 交互。

按钮 loading 状态

默认文字

默认的文字为 loading...

 Copy
按钮 - button 元素   
<button type="button" class="am-btn am-btn-primary btn-loading-example">Submit - Button</button>
<input type="button" class="am-btn am-btn-primary btn-loading-example" value="Submit - Input" />
 Copy
$('.btn-loading-example').click(function () {
var $btn = $(this)
$btn.button('loading');
setTimeout(function(){
$btn.button('reset');
}, 5000);
});

自定义选项

可以在元素上添加 data-am-loading 来设置选项:

  • spinner 加载动画图标,适用于支持 CSS3 动画、非 input 元素,写图标名称即可;
  • loadingText 加载时显示的文字, 默认为 loading
  • resetText 重置以后的显示的文字,默认为原来的内容。
 Copy
按钮 - button 元素   
<button type="button" class="am-btn am-btn-primary btn-loading-example" data-am-loading="{spinner: 'circle-o-notch', loadingText: '加载中...', resetText: '加载过了'}">按钮 - button 元素</button>

<input type="button" class="am-btn am-btn-secondary btn-loading-example" value="按钮 - input 元素" data-am-loading="{loadingText: '努力加载中...'}" />
 Copy
$('.btn-loading-example').click(function () {
var $btn = $(this)
$btn.button('loading');
setTimeout(function(){
$btn.button('reset');
}, 5000);
});

单按钮状态切换

 Copy
切换状态

按钮状态:未激活

<button id="doc-single-toggle" type="button" class="am-btn am-btn-primary" data-am-button>切换状态</button>

<p>按钮状态:<span id="doc-single-toggle-status" class="am-text-danger">未激活</span></p>

<script>
$(function() {
var $toggleButton = $('#doc-single-toggle');
$toggleButton.on('click', function() {
setButtonStatus();
}); function setButtonStatus() {
var status = $toggleButton.hasClass('am-active') ? '未激活' : '激活';
$('#doc-single-toggle-status').text(status);
}
})
</script>

复选框

注意:由于 FastClick 的原因,触屏设备上使用时需要在 input 上添加 .needsclick,否则无法获取复选框的值。

 Copy
苹果橘子香蕉
<div class="am-btn-group" data-am-button>
<label class="am-btn am-btn-primary">
<input type="checkbox" name="doc-js-btn" value="苹果"> 苹果
</label>
<label class="am-btn am-btn-primary">
<input type="checkbox" name="doc-js-btn" value="橘子"> 橘子
</label>
<label class="am-btn am-btn-primary">
<input type="checkbox" name="doc-js-btn" value="香蕉"> 香蕉
</label>
</div>
<script>
$(function() {
var $cb = $('[name="doc-js-btn"]');
$cb.on('change', function() {
var checked = [];
$cb.filter(':checked').each(function() {
checked.push(this.value);
}); console.log('复选框选中的是:', checked.join(' | '));
});
});
</script>

单选框

 Copy
选项 1选项 2选项 3选项 4
<div class="am-btn-group doc-js-btn-1" data-am-button>
<label class="am-btn am-btn-primary">
<input type="radio" name="options" value="选项 1" id="option1"> 选项 1
</label>
<label class="am-btn am-btn-primary">
<input type="radio" name="options" value="选项 2" id="option2"> 选项 2
</label>
<label class="am-btn am-btn-primary">
<input type="radio" name="options" value="选项 3" id="option3"> 选项 3
</label>
<label class="am-btn am-btn-primary am-disabled">
<input type="radio" name="options" value="选项 4" id="option4"> 选项 4
</label>
</div>
<script>
// 获取选中的值
$(function() {
var $radios = $('[name="options"]');
$radios.on('change',function() {
console.log('单选框当前选中的是:', $radios.filter(':checked').val());
});
});
</script>

设置默认选中状态

设置默认选中状态涉及两处:

  • <label> 上添加 am-active 类名(2.7.0+ 无需添加此类名);
  • <input> 上添加 checked 属性。
 Copy
苹果橘子香蕉
<div class="am-btn-group" data-am-button>
<!--默认选中状态设置-->
<label class="am-btn am-btn-primary am-active">
<input type="checkbox" class="needsclick" name="doc-js-btn" value="苹果" checked> 苹果
</label>
<label class="am-btn am-btn-primary">
<input type="checkbox" class="needsclick" name="doc-js-btn" value="橘子"> 橘子
</label>
<label class="am-btn am-btn-primary">
<input type="checkbox" class="needsclick" name="doc-js-btn" value="香蕉"> 香蕉
</label>
</div>

amazeui学习笔记--js插件(UI增强2)--按钮交互Button的更多相关文章

  1. amazeui学习笔记--js插件(UI增强)--警告框Alert

    amazeui学习笔记--js插件(UI增强)--警告框Alert 一.总结 1.警告框基本样式:用am-alert声明div容器, <div class="am-alert" ...

  2. amazeui学习笔记--js插件(UI增强4)--下拉组件Dropdown

    amazeui学习笔记--js插件(UI增强4)--下拉组件Dropdown 一.总结 1.am-dropdown(及其孩子):控制下拉列表的样式 2.data-am-dropdown(及其孩子):控 ...

  3. amazeui学习笔记--js插件(UI增强3)--折叠面板Collapse

    amazeui学习笔记--js插件(UI增强3)--折叠面板Collapse 一.总结 注意点: 1.data-am-collapse:这个东西就是展开折叠事件 2.am-collapse(包括其下属 ...

  4. amazeui学习笔记二(进阶开发1)--项目结构structure

    amazeui学习笔记二(进阶开发1)--项目结构structure 一.总结 1.项目结构:是说的amazeui在github上面的项目结构,二次开发amazeui用 二.项目结构structure ...

  5. amazeui学习笔记三(你来我往1)--常见问题FAQs

    amazeui学习笔记三(你来我往1)--常见问题FAQs 一.总结 1.DOM事件失败:记得加上初始化代码,例如 图片轮播 $('#my-slider').flexslider(); 2.jquer ...

  6. amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules

    amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules 一.总结 1.见名知意:见那些class名字知意,见函数名知意,见文件名知意 例如(HISTORY.md Web 组件更新历史 ...

  7. amazeui学习笔记二(进阶开发2)--Web组件简介Web Component

    amazeui学习笔记二(进阶开发2)--Web组件简介Web Component 一.总结 1.amaze ui:amaze ui是一个web 组件, 由模板(hbs).样式(LESS).交互(JS ...

  8. amazeui学习笔记一(开始使用3)--兼容性列表compatibility

    amazeui学习笔记一(开始使用3)--兼容性列表compatibility 一.总结 1.不要用ie做前端测试,不要碰ie,尽量用google 浏览器: 按照微软官方的说法,IE 开发者工具中的浏 ...

  9. amazeui学习笔记一(开始使用2)--布局示例layouts

    amazeui学习笔记一(开始使用2)--布局示例layouts 一.总结 1.样例分析(不要忘记,优先分析这个布局示例):有教你页面怎么布局的,实例中可以分析一波 2.响应式:对应meta标签中的v ...

随机推荐

  1. OpenCASCADE Job - 武汉中南

    中南设计集团(武汉)工程技术研究院有限公司是中南工程咨询设计集团有限公司(以下简称“中南设计集团”)打造的工程技术研发和科研创新平台,为中南设计集团旗下全资子公司,于2018年2月成立.公司业务范围涵 ...

  2. 高效的TCP数据拆包器

    高效的TCP数据拆包器 接收器,每秒拆1KB的包达到30万以上 /// 数据同步协义数据接收器 /// </summary> /// <remarks> /// 主要功能有 / ...

  3. Cisco PIX防火墙PPPoE拨号配置视频教学

    Cisco PIX防火墙PPPoE拨号配置视频教学   本文出自 "李晨光原创技术博客" 博客,请务必保留此出处http://chenguang.blog.51cto.com/35 ...

  4. IOS应用在ios7(iPhone5/iPhone5s)上不能全屏显示

    前言 [IOS应用在iOS7系统或者iPhone5/iPhone5s上不能全屏显示,应用画面上下各有1条黑色,但是在其他系统或者型号的手机上却是正常显示 Paste_Image.png Paste_I ...

  5. button按钮下边框有立体效果样式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. netty实现TCP长连接

    所用jar包 netty-all-4.1.30.Final.jar 密码:rzwe NettyConfig.java,存放连接的客户端 import io.netty.channel.group.Ch ...

  7. 47.Android 自己定义PopupWindow技巧

    47.Android 自己定义PopupWindow技巧 Android 自己定义PopupWindow技巧 前言 PopupWindow的宽高 PopupWindow定位在下左位置 PopupWin ...

  8. [AngularFire] Resolve snapshotChanges doesn't emit value when data is empty

    Updated to AngularFire2 v5.0. One important change is that you need to call .snapshotChanges() or .v ...

  9. Centos 6.8 安装 Protocol Buffers , v3.2.0有 BUG ,安装 3.1.0

    Centos 6.8 安装 Protocol Buffers   , v3.2.0有 BUG ,安装 3.1.0 切换到用户目录 cd ~ 安装 python2.7,须加入zlib wget http ...

  10. RingtoneManager-获得系统当前的铃声

    我们直接看代码 bt1 = (Button) findViewById(R.id.bt1); bt2 = (Button) findViewById(R.id.bt2); bt3 = (Button) ...