How to add and delete an input-group using jQuery Based on Bootstrap _ javascript

Source: Internet
Author: User
This article describes how to add and delete an input-group using jQuery Based on Bootstrap, for more information, see the examples in this article.

Note that you must use the input box Group of the Bootstrap framework, for example:

Demo case:

The self-made plugin inputGroup. js is provided here.

The parameter indicates whether the control in the input box group is a text field or an input box, and the operation content on the right of the input box group.

To use inputGroup. js, you only need to add a selector to the corresponding container, for example, p. Then, use jQuery to obtain the jQuery object corresponding to the selector and call the initInputGroup method.
InputGroup. js

/*** Created by DreamBoy on 2016/4/29. */$ (function () {$. fn. initInputGroup = function (options) {// 1. settings initialization Settings var c =$. extend ({'widget ': 'input', 'add': "", 'del': ""}, options); var _ this = $ (this ); // Add the addInputGroup (1) to the input box group with the serial number of 1;/*** Add the serial number of the input box group with the serial number of order * @ param order input box group number */function addInputGroup (order) {// 1. create input box group var inputGroup = $ ("

"); // 2. input box Group No. var inputGroupAddon1 = $ (""); // 3. set the serial number of the input box group inputGroupAddon1.html ("" + order + ""); // 4. create input controls (input or textarea) var widget = '', inputGroupAddon2; if (c. widget = 'textea ') {widget = $ (""); InputGroupAddon2 = $ (" ");} else if (c. widget = 'input') {widget = $ (""); InputGroupAddon2 =2 (" ") ;}// 5. Create the last operation button in the input box group var addBtn =$ (""+ C. add +""); AddBtn. appendTo (inputGroupAddon2 ). on ('click', function () {// 6. response to the delete and add OPERATION button event if({(this}.html () = c. del) {$ (this ). parents ('. input-group '). remove ();} else if(%(this%.html () = c. add) {signature (this).html (c. del); addInputGroup (order + 1);} // 7. resort () ;}); inputGroup. append (inputGroupAddon1 ). append (widget ). append (inputGroupAddon2); _ this. append (inputGroup);} function resort () {var child = _ this. children (); $. each (child, function (I) {$ (this ). find (". input-group-addon "2.16.eq(02.16.html ('' + (I + 1) + '');});}}});

Demo case -- InputGroupDemo
The directory structure is as follows:


Index.html

     
    
    
    Input box Group   
        
    
      

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.