【问题标题】:How to create an edit button work properly in CRUD?如何创建编辑按钮在 CRUD 中正常工作?
【发布时间】:2019-08-26 19:10:46
【问题描述】:

我正在做 CRUD 项目,总的来说我的代码是有效的。但是只有一个我的代码不能正常工作,那就是编辑按钮。

$("editable.btn-primary").click(function(){
      $(".table").find('tr').eq(this.value).each(function(){
        $("#username").val($(this).find('td').eq(1).text());
        $("#password").val($(this).find('td').eq(2).text());
        $(".btn-info").val($(this).find('td').eq(0).text());
      });
      $(".btn-info").attr("name", "edit");
    });

我希望当用户点击编辑按钮时数据可以编辑和更新

【问题讨论】:

  • 你能解释一下吗,不是clair

标签: javascript php html css


【解决方案1】:

可能是可编辑按钮动态生成的元素。

还要检查editable是否是一个类,你需要更改为.editable.btn-primary

$(document).on('click','editable.btn-primary',function(){
      $(".table").find('tr').eq(this.value).each(function(){
        $("#username").val($(this).find('td').eq(1).text());
        $("#password").val($(this).find('td').eq(2).text());
        $(".btn-info").val($(this).find('td').eq(0).text());
      });
      $(".btn-info").attr("name", "edit");
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多