如何将li更改为input type = text并保存新值?

时间:2018-04-11 07:23:32

标签: jquery html

我正在从' https://randomuser.me/api/'到学校做这个项目。 点击btn新用户将出现在带有编辑和删除按钮的自举卡中。 每个用户都有列表(li): 性别,姓名,电子邮件等。

点击性别值需要将li更改为输入(type =" text")并点击编辑需要保存更改。

1 个答案:

答案 0 :(得分:0)

以下是您所需的解决方案:

将以下代码添加到您的js:

 $('body').on('click','.edituser' ,function(){
      $( ".editing" ).each(function() {
        var input = $('<a class="edit" href="#">'+$(this).val()+'</a>');
            $(this).replaceWith(input);
      });
    })

它的作用:

  • 当您点击li按钮时,这将删除所有文本框并使其显示为edit

Here is a working Plunker