gpt4 book ai didi

javascript - 如何防止在 cleditor 中输入和粘贴单引号和双引号?

转载 作者:行者123 更新时间:2023-11-29 03:27:24 25 4
gpt4 key购买 nike

如何防止在 cleditor 中输入和粘贴单引号和双引号?如何防止在 cleditor 中输入和粘贴单引号和双引号?

<script type="text/javascript">
$(document).ready(function(){
$prevent_single_double_quote = function(e){
var element=e;
setTimeout(function () { element.val(element.val().replace(/['"]/g, "")); }, 1);
}
$('textarea').on('paste', function () {
$prevent_single_double_quote($(this));
});
$('textarea').on('keyup', function () {
$prevent_single_double_quote($(this));
});
$('input').on('paste', function () {
$prevent_single_double_quote($(this));
});
$('input').on('keyup', function () {
$prevent_single_double_quote($(this));
});
$('.scle').on('keyup', function () {
$prevent_single_double_quote($(this));
});
});
</script>

<div class="col-md-9">
<div class="block block-fill-white" id="mailcontent">
<div class="content np" id="mailcontent">
<textarea class="scle" name="mailcontent" id="mailcontent"></textarea>
</div>
</div>
</div>

最佳答案

$(document).ready(function() {
$prevent_single_double_quote = function(e) {
var element = e;
setTimeout(function() {
var regexFormat = /^[a-zA-Z0-9 ]*$/;
var text = element.val();
if(!regexFormat.test(text)){
//if contains single or double quotes.
text = text.substring(0, (text.length-1));
}
element.val(text);
}, 1);
};
$('textarea').on('change', function() {
$prevent_single_double_quote($(this));
});
$('textarea').on('keyup', function() {
$prevent_single_double_quote($(this));
});
$('input').on('change', function() {
$prevent_single_double_quote($(this));
});
$('input').on('keyup', function() {
$prevent_single_double_quote($(this));
});
$('.scle').on('keyup', function() {
$prevent_single_double_quote($(this));
});
});

希望这能奏效!

关于javascript - 如何防止在 cleditor 中输入和粘贴单引号和双引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34351624/

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