如何防止在 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/