gpt4 book ai didi

javascript - 在 simple_form 中禁用复制/粘贴功能

转载 作者:行者123 更新时间:2023-11-30 11:55:30 26 4
gpt4 key购买 nike

我正在尝试禁用 simple_form 输入字段中的复制/粘贴功能。我知道这已被问到 before在 simple_form 上下文之外。我按照 this 中的想法向表单本身添加了一个类发布,并在 application.js 的函数中使用该类。这目前没有产生所需的功能——是否有一种特殊的方法可以在 simple_form 中执行此操作?

(我知道不建议篡改默认浏览器功能,但“手动”复制的操作与我试图通过我的应用实现的目标一致)。

在 View 中:

<%= simple_form_for @word, url: lesson_word_exposition_path(current_lesson, @word.word), html: { class: "disablecopypaste"}, method: :patch do |f| %>
<%= f.input :term_given_by_student, label: "Enter the term exactly as above:" %><br>
<%= f.button :submit, class: 'btn btn-primary' %>
<% end %>

来自 application.js:

$(document).ready(function () {
$('input.disablecopypaste').bind('copy paste', function (e) {
e.preventDefault();
});
});

最佳答案

您可以尝试使用 user-select css 属性。

.unselectable : {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}


$(document).ready(function () {
$('input.disablecopypaste').toggleClass('unselectable')
});

关于javascript - 在 simple_form 中禁用复制/粘贴功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38109355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com