所以我有一个自定义文本框指令(它内部包含一个输入框)。
<custom-textbox ng-paste=pasteFn($event)></custom-textbox>
当用户点击粘贴时,我想清理粘贴的内容(删除特殊字符+减少字符串长度)。
我尝试查看事件对象,它看起来相当大,因此我不确定修改此字符串的最佳方法。
最佳答案
获取剪贴板数据并将其发送到您的粘贴函数,如下所示:
<input ng-paste="clean($event.clipboardData.getData('text/plain'))" placeholder='paste here' ng-model="paste">
pasted: {{paste}}<br>
new string: {{myString}}
然后在你的 Controller 中:
$scope.clean = function(e){
var str = e;
$scope.myString = str.replace(/[^a-zA-Z ]/g, "");
}
这是一个Plunker
关于javascript - 如何修改粘贴事件的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39475875/