[英]How to disable ctrl+v (paste) function in a JSF page ?. I am using primefaces component.
I have an inputText component where i am accepting only integer values by validating through keyup event. 我有一个inputText组件,我通过keyup事件验证只接受整数值。 but i am not able to disable ctrl+v option so the user is able to paste string value into the input text box.
但我无法禁用ctrl + v选项,因此用户可以将字符串值粘贴到输入文本框中。 html has onpaste option but JSF does not!
html有onpaste选项,但JSF没有! Thanks in advance.
提前致谢。
With JSF 2.2 you can "pass through" attributes to be rendered via <f:passThroughAttribute />
and you would be able to add something like onpaste="return false;"
使用JSF 2.2,您可以“通过”通过
<f:passThroughAttribute />
呈现的属性,并且您可以添加类似onpaste="return false;"
, but I assume you do not use JSF 2.2 yet. ,但我认为你还没有使用JSF 2.2。
You can still easily disable copy-pasting via some custom javascript. 您仍然可以通过一些自定义JavaScript轻松禁用复制粘贴。 With standard javascript this is as easy as this (taken from here ):
使用标准的javascript,这很简单(取自此处 ):
window.onload = function() {
var myInput = document.getElementById('myInput');
myInput.onpaste = function(e) {
e.preventDefault();
}
}
With jQuery you can do it like this (taken from here ): 使用jQuery,你可以这样做(取自这里 ):
$(document).ready(function(){
$('#myInput').bind("cut copy paste",function(e) {
e.preventDefault();
});
});
The jQuery option is also nice, because you can easily do this with all inputs on your site using a combination of the above code and $('input').each
jQuery选项也很不错,因为您可以使用上述代码和
$('input').each
的组合轻松地对您网站上的所有输入执行此操作$('input').each
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.