0

Подскажите пожалуйста, есть код в котором по нажатию на span изменяется на input.

$(function () {
    //Loop through all Labels with class 'editable'.
    $(".editable").each(function () {
        //Reference the Label.
        var label = $(this);
 
        //Add a TextBox next to the Label.
        label.after("<input type = 'text' style = 'display:none' />");
 
        //Reference the TextBox.
        var textbox = $(this).next();
 
        //Set the name attribute of the TextBox.
        textbox[0].name = this.id.replace("lbl", "txt");
 
        //Assign the value of Label to TextBox.
        textbox.val(label.html());
 
        //When Label is clicked, hide Label and show TextBox.
        label.click(function () {
            $(this).hide();
            $(this).next().show();
        });
 
        //When focus is lost from TextBox, hide TextBox and show Label.
        textbox.focusout(function () {
            $(this).hide();
            $(this).prev().html($(this).val());
            $(this).prev().show();
        });
    });
});
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<span id="lblName" class="editable">Mudassar</span><p>Изменить</p>

Как сделать что бы при нажатии на текст изменить span изменялся на input?

1
  • У вас текст изменить не в span находится, а в p. 25 окт 2018 в 16:03

1 ответ 1

0

Вместо замены span на input можно использовать атрибут contenteditable="true".

<span id="lblName" contenteditable="true" class="editable">Mudassar</span><p contenteditable="true">Изменить</p>

1
  • Нужно при нажатии на текст "изменить" span изменялся в input. p не трогаем. 26 окт 2018 в 6:16

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.