问题
I am developing a Hybrid application using IBM Worklight, HTML5, CSS3 and javascript. Is there any possible way to disable text selection on input fields?
I have a username and password field on the screen and want to disable the user from selecting text within the input fields. Also, copy paste should be disabled.
Thanks
回答1:
There is an answer already on SO for selecting that will probably give you what you need: Prevent element from taking part in text selection
There are also answers on SO for disabling pasting on some browsers: Disable pasting text into HTML form
Keep in mind though that the above will not work in every browser.
回答2:
To disable pasting text into input field,
$('#myInput').bind('input', function(e) {
$("#myInput").val(""); //This will reset input value to empty
});
回答3:
you can use below code to disable copy and paste
$('input,textarea').bind('cut copy paste', function (e) {
e.preventDefault(); //disable cut,copy,paste
});
来源:https://stackoverflow.com/questions/22773049/disable-text-selection-on-input-fields