html - 我无法使用 angularjs 在文本框中粘贴中文内容
问题描述
<input type="text" class="form-control name" name="name" id="focus_me" required maxlength="50" letters-with-space="" ng-trim="false" tabindex="1" ng-model="vm.detail.name" ng-paste="paste($event.originalEvent)" ng-init="vm.detail.name = null">
$scope.paste = function (event,field) {
var item = event.clipboardData.items[0];
item.getAsString(function (data) {
$scope.pastedData = data;
$scope.$apply();
});
}
输入:继续
这是输入,我无法将其粘贴到文本框中。如何启用它?
解决方案
查看此https://jsfiddle.net/geekcode/s91t2ryg/11/
我可以粘贴中文内容,只是通过$event
而不是$event.originalEvent
.
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="ctrl">
<input ng-model="mod" type="text" ng-paste="paste($event)" ng-init="mod = null">
{{mod}}
<input ng-model="mod1" type="text">
</div>
</div>
<script>
var app = angular.module("app", []);
app.controller("ctrl", function($scope){
$scope.paste = function (event,field) {
var item = event.clipboardData.items[0];
item.getAsString(function (data) {
$scope.pastedData = data;
$scope.$apply();
});
}
});
</script>
推荐阅读
- python - 我如何访问 gsp 电子表格中的工作表名称。工作表()
- airflow - 在时区感知 DAG 中,next_ds 在夏令时期间的行为是否正确?
- ios - 我需要以编程方式在智能电视上显示来自 iphone 的视频
- c# - Audit.Net MVC - 如何解决 NullReferenceException?
- reactjs - 为什么在输入更改时重新渲染功能组件中的所有元素
- javascript - moment.utc('date string').format('DD-MMM-YYYY') 返回上一个日期
- c# - 在不同的机器 C# 中生成和签署证书
- jquery - JQuery .nextUntil() 选择标题进入 li
- javascript - 如何创建多个popper实例?
- r - 如果 X 中的列为 FALSE,则删除 Y 中的相同列?