javascript - 如何删除最后执行的命令html + javascript?
问题描述
我有两个页面,第 1 页和第 2 页。对于第 2 页,我的代码是这样的:
$("input[value]").each(function(r) {
if (r == 6) {
$(this).focus();
document.execCommand("insertText", false, request.data.email);
setTimeout(() => {
document.execCommand("delete", false, null);
console.log('deleted')
}, 3000);
}
});
我已成功将文本复制到输入,但如果我移动到第 1 页,然后再次回到第 2 页,然后调用该函数,我仍然看到我之前复制的原始数据仍然存在。
我的问题:如何删除最后一个命令document.execCommand("insertText", false, request.data.email);
?我尝试过类似这样document.execCommand("delete", false, null);
的命令:,但它不起作用。
解决方案
使用undo
command,delete
将删除当前选择,而不是最后一个命令:
$("input[value]").each(function(r) {
if (r == 6) {
$(this).focus();
document.execCommand("insertText", false, request.data.email);
setTimeout(() => {
document.execCommand("undo", false, null);
console.log('undone')
}, 3000);
}
});
推荐阅读
- python - 在 Python 中,是否有一个内置函数来获取两个给定值之间的值(在列表中)?
- verilog - 多位门
- node.js - 为什么我的 XMLHttpRequest POST 并不总是发送到服务器?
- python - 如何在opencv python中放置停留时间
- javascript - React Usestate 将状态设置为 false,我正在使用其中包含对象的数组
- php - 需要 curl 等待响应直到下一次执行
- c# - 在 dotnet core 3.1 中使用 IAuthorizationPolicyProvider 的自定义实现进行身份验证
- node.js - MongoDB - 我怎样才能获得最高的 Int
- reactjs - ReactJS 中的递增/递减函数
- excel - 将文件从一个文件夹移动到另一个文件夹 - 错误 53 找不到文件