[英]sweetalert2 textarea newline confirm the modal
當我嘗試在textarea輸入類型中換行時,已確認模式。
我也添加了這些,但是什么也沒有發生:allowEnterKey:false,focusConfirm:false,
有人建議我的問題嗎?
在此處檢查代碼:
https://jsfiddle.net/piman/f28tn8hq/24/
$('.table button').on('click', function () { var replycontent = jQuery("#replyid-7 #reply-content").text(); swal({ title: 'my Title', type: 'question', input: 'textarea', inputValue: replycontent, showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Save', cancelButtonText: 'Cancel', allowEnterKey: false, focusConfirm: false, inputValidator: function (value) { return new Promise(function (resolve, reject) { if (value) { resolve() } else { reject('Error!') } }) } } ).catch(swal.noop) });
<link href="https://limonte.github.io/sweetalert2/assets/example.css" rel="stylesheet"/> <script src="https://limonte.github.io/sweetalert2/dist/sweetalert2.all.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="table-responsive"> <table class="table"> <tbody> <tr id="replyid-7"> <td> <p id="reply-content">Any Text here <br> New line Test</p> <hr> <div class="author-info">by Admin</div> <button>EDIT Content</button> </td> </tr> </tbody> </table> </div>
使用以下控件。 但是有一個錯誤,按Enter鍵后,光標移至文本區域的末尾。
$('body').on('keydown','textarea', function(e) {
if(e.which === 13){
e.preventDefault();
var value = e.target.value;
var start = e.target.selectionStart;
var end = e.target.selectionEnd;
if(start === end){
value = value.substring(0, start) + "\n" + value.substring(start, value.length);
}else{
value = value.substring(0, start) + "\n" + value.substring(end, value.length);
}
//TODO - set curser position to (start + 1)
e.target.value = value;
}
return e.which !== 13;
});
這是jsfiddle鏈接: https ://jsfiddle.net/rosfc6r2/
我已更新到最新版本。 它已經修復了!
嘗試使用以下功能解決此問題。
$('#id').on('keyup keypress', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) { // enter key
e.preventDefault();
return false;
}
})
在現代瀏覽器上,您還可以使用“ e.which”:
$('#id').on('keypress', function(e) {
return e.which !== 13;
});
希望這對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.