3 回答

TA貢獻1848條經驗 獲得超2個贊
Asp 控件在運行時更改 id,因此您無法捕獲給定的 id。
因此,要捕獲實際 ID:
選項1。
var $editor = ("#<%= editor.ClientID %>");
選項2,使用ClientIDMode="static"
。
<asp:TextBox ID="editor" ClientIDMode="static">...</asp:TextBox>

TA貢獻1834條經驗 獲得超8個贊
綁定到粘貼事件,您必須設置超時以確保填充粘貼的值。原因是,粘貼事件不是立即發生的(4 毫秒),因此超時迫使隊列進入概念順序。
$("#foo").on('paste', function(e) { // <---- e, event
var pastedData = e.target.value;
setTimeout(function() {
console.log($(e.currentTarget).val());
}, 0);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea id="foo" rows="20" cols="50">
I am a working textbox example
</textarea>

TA貢獻1784條經驗 獲得超8個贊
我已經弄清楚如何捕獲粘貼的文本,這里是一個更新的 jquery 函數
$(document).ready(function() {
var $editor = $('#editor');
$editor.on('paste, keydown', function() {
var $self = $(this);
setTimeout(function(){
var $oldContent = $self.text(); // The old content in the control
var $pastedContent = $editor.val(); // Pasted content
// Clean data to meet requirements
$pastedContent = #pastedContent.replace(/(\r\n|\n|\r|\s+)/gm, " ");
$editor.val($pastedContent);
},100);
});
});
感謝所有提供幫助的人。
添加回答
舉報