在HTML输入字段中禁用复制粘贴? [英] Disable copy paste in HTML input fields?
本文介绍了在HTML输入字段中禁用复制粘贴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能存在重复:
禁用复制/粘贴到使用Javascript的HTML表单
我的银行似乎已禁用复制粘贴用户名和密码。
My bank seem to have disabled copy-paste of username and password.
它是如何完成的?它会提高安全性吗?
How is it done? Does it improve security?
推荐答案
您可以在输入中禁用粘贴,如下所示:
You can disable paste in your input as follows:
html:
html:
<input type="text" value="" id="myInput">
javascript:
javascript:
window.onload = function() {
const myInput = document.getElementById('myInput');
myInput.onpaste = function(e) {
e.preventDefault();
}
}
谈到安全性,我不会说这个会产生任何影响。您通常会使用客户端和服务器端验证用户提交的数据。
Talking about security, I wouldn't say that this makes any impact. You would usually use client side and well as server-side validation of data submitted by the user.
希望这可以帮助
这篇关于在HTML输入字段中禁用复制粘贴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文