Javascript 按Esc按钮后还原为原始html

Javascript 按Esc按钮后还原为原始html,javascript,jquery,html,Javascript,Jquery,Html,我通过javascript修改了一个html,我希望当我单击esc时,它会返回到html的原始形式: if ($("#div").show()) { $("#div1").empty(); $("#div1").html("<input class='tabledit-input form-control' type='text' value='" + file[0].name + "'>"); $("#div2").empty(); $("#div

我通过javascript修改了一个html,我希望当我单击esc时,它会返回到html的原始形式:

if ($("#div").show()) {
    $("#div1").empty();
    $("#div1").html("<input class='tabledit-input form-control' type='text' value='" + file[0].name + "'>");

    $("#div2").empty();
    $("#div2").html("<input type='text' class='form-control' placeholder='div2'>");

    $("#div3").empty();
    $("#div3").html("<input type='text' class='form-control' placeholder='div3'>");
} else if (e.keyCode == 27) {
    //what to do here?
}
if($(“#div”).show()){
$(“#div1”).empty();
$(“#div1”).html(“”);
$(“#div2”).empty();
$(“#div2”).html(“”);
$(“#div3”).empty();
$(“#div3”).html(“”);
}否则如果(e.keyCode==27){
//在这里做什么?
}
您可以使用
.clone()
方法在事件发生之前克隆原始克隆:

//#################  clone them here ######################

var d1 = $("#div1").clone(),
    d2 = $("#div2").clone(),
    d3 = $("#div3").clone();
现在,您可以将其替换为:

if ($("#div").show()) {
    $("#div1").empty();
    $("#div1").html("<input class='tabledit-input form-control' type='text' value='" + file[0].name + "'>");

    $("#div2").empty();
    $("#div2").html("<input type='text' class='form-control' placeholder='div2'>");

    $("#div3").empty();
    $("#div3").html("<input type='text' class='form-control' placeholder='div3'>");
} else if (e.keyCode == 27) {
    //################# now replace it here. ####################
    $('#div1').replaceWith(d1);
    $('#div2').replaceWith(d2);
    $('#div3').replaceWith(d3);
}
if($(“#div”).show()){
$(“#div1”).empty();
$(“#div1”).html(“”);
$(“#div2”).empty();
$(“#div2”).html(“”);
$(“#div3”).empty();
$(“#div3”).html(“”);
}否则如果(e.keyCode==27){
//#################现在把它换到这里####################
$(#div1')。替换为(d1);
$(#div2')。替换为(d2);
$(#div3')。替换为(d3);
}
您可以使用
.clone()
方法在事件发生之前克隆原始克隆:

//#################  clone them here ######################

var d1 = $("#div1").clone(),
    d2 = $("#div2").clone(),
    d3 = $("#div3").clone();
现在,您可以将其替换为:

if ($("#div").show()) {
    $("#div1").empty();
    $("#div1").html("<input class='tabledit-input form-control' type='text' value='" + file[0].name + "'>");

    $("#div2").empty();
    $("#div2").html("<input type='text' class='form-control' placeholder='div2'>");

    $("#div3").empty();
    $("#div3").html("<input type='text' class='form-control' placeholder='div3'>");
} else if (e.keyCode == 27) {
    //################# now replace it here. ####################
    $('#div1').replaceWith(d1);
    $('#div2').replaceWith(d2);
    $('#div3').replaceWith(d3);
}
if($(“#div”).show()){
$(“#div1”).empty();
$(“#div1”).html(“”);
$(“#div2”).empty();
$(“#div2”).html(“”);
$(“#div3”).empty();
$(“#div3”).html(“”);
}否则如果(e.keyCode==27){
//#################现在把它换到这里####################
$(#div1')。替换为(d1);
$(#div2')。替换为(d2);
$(#div3')。替换为(d3);
}