基于Bootstrap使用jQuery实现输入框组input-group的添加与删除-改进版
- /**
- * Created by DreamBoy on 2016/6/4.
- */
- /**
- * Created by DreamBoy on 2016/4/29.
- */
- $(function() {
- $.fn.initInputGroup = function (options) {
- //1.Settings 初始化设置
- var c = $.extend({
- widget: 'input',
- add: "<span class=\"glyphicon glyphicon-plus\"></span>",
- del: "<span class=\"glyphicon glyphicon-minus\"></span>",
- field: '',
- data: []
- }, options);
- var _this = $(this);
- _this.children().remove();
- //添加序号为1的输入框组
- addInputGroup(1);
- /**
- * 添加序号为order的输入框组
- * @param order 输入框组的序号
- * @param data 初始化输入框组中的数据
- */
- function addInputGroup(order) {
- //1.创建输入框组
- var inputGroup = $("<div class='input-group' style='margin: 10px 0'></div>");
- //2.输入框组的序号
- var inputGroupAddon1 = $("<span class='input-group-addon'></span>");
- //3.设置输入框组的序号
- inputGroupAddon1.html(" " + order + " ");
- //4.创建输入框组中的输入控件(input或textarea)
- var widget = '', inputGroupAddon2;
- if(c.widget == 'textarea') {
- widget = $("<textarea class='form-control' style='resize: vertical;'></textarea>");
- widget.html(c.data[order - 1]);
- inputGroupAddon2 = $("<span class='input-group-addon'></span>");
- } else if(c.widget == 'input') {
- widget = $("<input class='form-control' type='text'/>");
- widget.val(c.data[order - 1]);
- inputGroupAddon2 = $("<span class='input-group-btn'></span>");
- }
- //5.设置表单提交时的字段名
- if(c.field.length == 0) {
- widget.prop('name', c.widget + 'Data[]');
- } else {
- widget.prop('name', c.field + '[]');
- }
- //6.创建输入框组中最后面的操作按钮
- var addBtn = $("<button class='btn btn-default' type='button'>" + c.add + "</button>");
- addBtn.appendTo(inputGroupAddon2).on('click', function() {
- //7.响应删除和添加操作按钮事件
- if($(this).html() == c.del) {
- $(this).parents('.input-group').remove();
- } else if($(this).html() == c.add) {
- $(this).html(c.del);
- addInputGroup(order+1);
- }
- //8.重新排序输入框组的序号
- resort();
- });
- inputGroup.append(inputGroupAddon1).append(widget).append(inputGroupAddon2);
- _this.append(inputGroup);
- if(order + 1 > c.data.length) {
- return;
- }
- addBtn.trigger('click');
- }
- function resort() {
- var child = _this.children();
- $.each(child, function(i) {
- $(this).find(".input-group-addon").eq(0).html(' ' + (i + 1) + ' ');
- });
- }
- }
- });
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>输入框组——改进版</title>
- <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
- <!--<link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />-->
- <!--[if lt IE 9]>
- <script src="js/html5shiv.js"></script>
- <script src="js/respond.min.js"></script>
- <![endif]-->
- </head>
- <body>
- <div class="container">
- <div class="input-group-add">
- </div>
- </div>
- <script src="js/jquery-1.11.1.min.js"></script>
- <script src="js/bootstrap.min.js"></script>
- <script src="inputGroup-1.1.js"></script>
- <script>
- $(function() {
- $('.input-group-add').initInputGroup({
- 'widget' : 'input', //输入框组中间的空间类型
- /*'add' : '添加',
- 'del' : '删除'*/
- 'field': 'data',
- 'data' : ['haha', 'hello', 'hi', 'dj']
- });
- });
- </script>
- </body>
- </html>
基于Bootstrap使用jQuery实现输入框组input-group的添加与删除-改进版的更多相关文章
- Bootstrap<基础十五> 输入框组
Bootstrap 支持的另一个特性,输入框组.输入框组扩展自 表单控件.使用输入框组,可以很容易地向基于文本的输入框添加作为前缀和后缀的文本或按钮. 通过向输入域添加前缀和后缀的内容,您可以向用户输 ...
- Bootstrap历练实例:输入框组的大小
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 基于Bootstrap的JQuery TreeView树形控件,数据支持json字符串、list集合(MVC5)<二>
上篇博客给大家介绍了基于Bootstrap的JQuery TreeView树形控件,数据支持json字符串.list集合(MVC5)<一>, 其中的两种方式都显得有些冗余.接着上篇博客继续 ...
- 基于bootstrap的jQuery多级列表树插件 treeview
http://www.cnblogs.com/mfc-itblog/p/5233453.html http://www.htmleaf.com/jQuery/Menu-Navigation/20150 ...
- 基于bootstrap的jQuery多级列表树插件
简要教程 bootstrap-treeview是一款效果非常酷的基于bootstrap的jQuery多级列表树插件.该jQuery插件基于Twitter Bootstrap,以简单和优雅的方式来显示一 ...
- Bootstrap 基于Bootstrap和JQuery实现动态打开和关闭tab页
基于Bootstrap和JQuery实现动态打开和关闭tab页 by:授客 QQ:1033553122 1. 测试环境 JQuery-3.2.1.min.j Bootstrap-3.3.7-d ...
- 基于Bootstrap的jQuery开关按钮组合
Bootstrap是一款由Twitter推出的开源前端开发包,功能非常强大.今天我们要分享的这款jQuery开关按钮组合就是基于Bootstrap框架的,看了按钮的主题样式,也都是Bootstrap的 ...
- 从零开始学 Web 之 jQuery(四)元素的创建添加与删除,自定义属性
大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表单:输入框(Input)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
随机推荐
- [svc]centos7安装优化最佳姿势
源/软件/时区/selinux/ulimit/vim/sshd 下载安装: https://mirrors.aliyun.com/centos/7.4.1708/isos/x86_64/CentOS- ...
- linux 建立反向shell
首先是netcat的版本选择BSD版的不支技-c -e参数,而GNU版的有-e参数,这里我用的是GNU版: sh-4.1# nc -V netcat (The GNU Netcat) Copyrigh ...
- angular学习笔记(二十七)-$http(5)-使用$http构建RESTful架构
在angular中有一个特别为RESTful架构而定制的服务,是在$http的基础上进行了封装. 但是为了学习,我们先看看用直接$http是如何构建RESTful架构的: 假设有一个银行卡的列表.需要 ...
- 旋转加载loading和点点加载loadingdemo
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- eclipse 项目中的java文件没有在WEB-INF目录下的classes中 生成相对应的编译后的类
1.首先确定project->Build Automatically是否勾选上: 2.执行完第一步之后测试一下看是否能编译,如果还是不能,则进行手动编译: 3,进入clean对话框,选择Cle ...
- PLSQL Developer新手使用教程(图文教程)
PLSQL Developer是Oracle数据库开发工具,很牛也很好用,PLSQL Developer功能很强大,可以做为集成调试器,有SQL窗口,命令窗口,对象浏览器和性能优化等功能,下面简单的介 ...
- 被linux线程基础折磨的点滴——还是没得到完美的答案,但至少得到了所需
#include<sys/types.h> #include<unistd.h> #include<stdio.h> #include<stdlib.h> ...
- dp之分组背包hdu3033 最少取1次的解法(推荐)
题意:有n双鞋子,m块钱,k个品牌,(一个品牌可以有多种价值不同的鞋子),接下来n种不同的鞋子,a为所属品牌,b为要花费的钱,c为所能得到的价值.每种价值的鞋子只会买一双,有个人有个伟大的梦想,每个品 ...
- 教程-TObjectList.Clear、TStringList.Clear方法对象有没有被释放
相关资料: http://www.cnblogs.com/rogge7/p/4631796.html delphiTStringList通过AddObject方法添加对象. object里存的只是指向 ...
- 利用IT++搭建通信仿真平台
IT++ is a C++ library of mathematical, signal processing and communication classes and functions.也就是 ...