【发布时间】:2014-04-14 10:28:05
【问题描述】:
我正在寻找有关如何为表单实现逐步撤消的帮助/想法。我已经能够达到一个单一的撤消事件,但我不知道如何更进一步。
在我的example 中,用户正在制作一个排序列表。他们选择他们的项目:
<input type="checkbox" id="food1">Bread<br>
<input type="checkbox" id="food2">Milk<br>
<input type="checkbox" id="food3">Juice<br>
<input type="checkbox" id="item1">Paper<br>
<input type="checkbox" id="item2">Pencils<br>
<input type="checkbox" id="item3">Eraser<br>
出现在方框中:<textarea id="text" rows="10" cols="25"></textarea>
列表是使用以下脚本生成的:
// variable literals
foodtype = {
food1: "Bread\n",
food2: "Milk\n",
food3: "Juice\n"
};
itemtype = {
item1: "Paper\n",
item2: "Pencils\n",
item3: "Eraser\n"
};
// new text
var textbox = $('#text').val();
// old text to revert to
var oldtext = '';
// temporary holder for checkbox id
var choice = null;
// fill textarea with list
function filltext1() {
if (choice !== null) {
if (choice.indexOf('food') != -1) {
textbox += foodtype[choice] + '';
choice = null;
$('#text').val(textbox);
} else if (choice.indexOf('item') != -1) {
textbox += itemtype[choice] + '';
choice = null;
$('#text').val(textbox);
}
}
}
// add new selection to list, unless unchecked
$('input:checkbox').change(function () {
if ($(this).is(':checked')) {
choice = $(this).attr('id');
oldtext = textbox;
filltext1();
} else {
$('#text').val(oldtext); // if unchecked, textarea = prior text
textbox = oldtext; // reset variable to prior text
}
});
最后一点是我的文本框,如果一个项目未被选中,则后退一步。但是,只有当您取消选中最近的选择时。
一个框的异步取消选中不会删除该项目的条目 - 而只是最后一个选择。
如何将初始选择链接到可以还原的状态?或者换一种说法,有没有办法异步撤销项目进入列表?如果这是可能的,我什至会对顺序撤消感到满意。
感谢您的帮助!
【问题讨论】:
标签: javascript jquery html undo