Change Label to Textbox on edit hyperlink click

前端 未结 5 1072
花落未央
花落未央 2020-12-05 09:01

I am new to ruby on rails and twitter bootstrap. Accept my apologize if my question sound dumb. I am using twitter bootstrap for my site design. I have been trying to use b

5条回答
  •  醉话见心
    2020-12-05 09:13

    As Chris said, Bootstrap does not provide this functionality as it is a front-end framework. you can use jQuery to achieve this. Though, you'll need to add some custom id's or classes to your elements to make sure you are only selecting the required elements. You can do something like the following:

    HTML

    jQuery

    $(document).ready(function() {
        $('a.edit').click(function () {
            var dad = $(this).parent().parent();
            dad.find('label').hide();
            dad.find('input[type="text"]').show().focus();
        });
    
        $('input[type=text]').focusout(function() {
            var dad = $(this).parent();
            $(this).hide();
            dad.find('label').show();
        });
    });
    

    CSS

    .edit-input {
        display:none;
    }
    

    Here is a working JSFiddle for your reference.

提交回复
热议问题