如何恢复文本框数据 [英] How to restore Textbox Data
本文介绍了如何恢复文本框数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小要求,
我们已经恢复了以前清除过的文本框数据。
下面是我的HTMl代码
We have restore the textbox data that was cleared previously.
Below is my HTMl code
<table>
<tr><td><input type="textbox"></td></tr>
<tr><td><input type="checkbox"></td></tr>
</table>
这是我的JQuery代码
Here is my JQuery Code
$('TABLE TR TD').find(':checkbox').change(function()
{
if($(this).prop('checked'))
{
$(this).parents('TR').siblings('TR').find('input').val("")
}
if(!$(this).prop('checked'))
{
$(this).parents('TR').siblings('TR').find('input').val(?)
}
});
如果选中复选框,我的要求是清除文本框内容。如果我取消选择它,应该使用以前的数据恢复文本框。
My Requirement is to clear the textbox content if checkbox is checked. And if i deselect it the textbox should be restored with previous data.
请有人帮帮我。
推荐答案
使用全局变量来存储以前的数据 -
Use a global variable to store the previous data -
var prevData;
然后以这种方式修改你的代码 -
then modify your code this way -
$('TABLE TR TD').find(':checkbox').change(function()
{
if($(this).prop('checked'))
{
var $element = $(this).parents('TR').siblings('TR').find('input')
prevData = $element.val();
$element.val("");
}
else
{
$(this).parents('TR').siblings('TR').find('input').val(prevData);
}
});
这篇关于如何恢复文本框数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文