首页 > 解决方案 > 我无法使用 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();
});
}

输入:继续

这是输入,我无法将其粘贴到文本框中。如何启用它?

标签: htmlangularjs

解决方案


查看此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>


推荐阅读