gpt4 book ai didi

javascript - sweetalert2 textarea 换行确认模态

转载 作者:行者123 更新时间:2023-11-30 14:56:24 25 4
gpt4 key购买 nike

当我尝试在文本区域输入类型中换行时,模式已确认。

我也添加了这些,但没有任何反应:allowEnterKey:假,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>

最佳答案

使用以下控件。但是有一个错误,在按下回车后,光标会移动到文本区域的末尾。

$('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/

关于javascript - sweetalert2 textarea 换行确认模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47210208/

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