Я реализовал код, который, когда я выделяю слово или фразу, добавляется в текстовую область, но как только я щелкаю мышью, выделенное текстовое значение выходит из текстовой области.
Я реализую это с помощью Angularjs.
This is my HTML & Angularjs code:
<div ng-app="myApp" ng-controller="caseCtrl">
<form name="aform" >
<textarea id="sel" rows="5" cols="20"></textarea>
</form>
<div>
<p>highlight the text to paste it in textbox.</p>
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('caseCtrl', function($scope) {
function getSelectionText() {
var text = "";
if ((activeElTagName == "textarea")) {
} else if (window.getSelection) {
text = window.getSelection().toString();
}
return text;
}
document.onclick = function() {
document.getElementById("sel").value = getSelection();
};
});
</script>
когда я выделяю текст, он вставляется в текстовое поле, но когда я щелкаю мышью, текст исчезает из текстового поля. Подскажите что мне делать?