Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 隐藏后保留输入值_Javascript_Jquery - Fatal编程技术网

Javascript 隐藏后保留输入值

Javascript 隐藏后保留输入值,javascript,jquery,Javascript,Jquery,我有一个编辑功能,如果我单击“编辑”,它们是一个具有隐藏/显示功能的功能。我的问题是,如果我要隐藏行的值,如何保持该行的值 例如,我有一个对话框 并决定编辑示例1(第一行) 然后我决定我意识到我不想编辑样本1,然后关闭它(再次单击编辑),然后我想编辑样本5,但我得到了这个错误 这是我的脚本 //show and hide update button checker function update_contain(){ var row = jQuery(".beneficiaries

我有一个编辑功能,如果我单击“编辑”,它们是一个具有隐藏/显示功能的功能。我的问题是,如果我要隐藏行的值,如何保持该行的值

例如,我有一个对话框

并决定编辑示例1(第一行)

然后我决定我意识到我不想编辑样本1,然后关闭它(再次单击编辑),然后我想编辑样本5,但我得到了这个错误

这是我的脚本

//show and hide update button checker
function update_contain(){
    var row = jQuery(".beneficiaries_rows input[type='text']:visible").length;
    if(row > 0){
        jQuery('.ui-dialog-buttonpane button:contains("Update")').button().show();
    }else{
        jQuery('.ui-dialog-buttonpane button:contains("Update")').button().hide();
        }
    }


//beneficiaries edit
jQuery(".edit_beneficiaries").click(function(){
  var row = jQuery(this).closest(".beneficiaries_rows");
  var show = row.find(".hide");
  var hide = row.find(".show");
  if(jQuery(show).is(":visible")){
    jQuery(show).css({"display":"none"});
    jQuery(hide).css({"display":"inline-block"});
  }else{
    jQuery(hide).css({"display":"none"});
    jQuery(show).css({"display":"inline-block"});
  }
  update_contain();
});
HTML

<table style="border: 2px solid black;margin:auto;">
    <tr>
        <th style="width:145px;"><center>Name<center></th>
        <th><center>Action</center></th>
    </tr>
    <?php
        while($row1 = mysql_fetch_array($result1)){
            echo "<tr class='beneficiaries_rows' id='".$row1['id']."' data-id='".$row1['ben_id']."'>";
            echo "<td><input class='hide' type='text' name='bename_update' value='".$row1['name']."'></div>";
            echo "<div class='show'>".$row1['name']."</td>";
            echo "<td>";
            echo "<center><button class='del_beneficiaries'>X</button><button class='edit_beneficiaries'>Edit</button></center>";
            echo "</td>";
            echo "</tr>";
        }
    ?>
</table>

名称
行动

您需要在标签内设置如下内容的文本

jQuery(“[selector for your label]”)html(jQuery(“[selector for input]”)val())

我建议在您隐藏输入之前,单击执行此操作

编辑;因为你没有真正的跟随:

jQuery(".edit_beneficiaries").click(function(){
    var row_display = jQuery(this).parents("tr").find(".show");
    var row_edit = jQuery(this).parents("tr").find(".hide");
    jQuery(row_display).html(jQuery(row_edit).val());
});

所以我要把sir放在click函数上面?正如我在回答中所建议的,你应该把它放在click函数中。我不知道它是否正确,但我尝试了这个
var x=jQuery(“tr”).html(jQuery(“.u行输入[type='text']”)val())$(“.edit_”)
时更改div的值。进一步的解释将从你的问题转移到教你如何编码。我建议尝试一些jQuery教程,以及一些关于CSS/jQuery选择器的教程