在指定位置的 HTML 输入/文本区域中插入文本
Insert Text in HTML Input / Textarea at Specified Position
在AngularJS中,我们如何插入一段文字,比如我想在第7位插入文字,单词"My "
之前
<textarea type="text">This is Text</textarea>
之后
<textarea type="text">This is My Text</textarea>
你可以试试这个。
$scope.text = $scope.insertText('This is Text', ' My', 7);
$scope.insertText = function(source, text, position) {
var subStr = source.substring(0, position);
return subStr + text + source.substring(subStr.length);
}
<textarea type="text">{{text}}</textarea>
在AngularJS中,我们如何插入一段文字,比如我想在第7位插入文字,单词"My "
之前
<textarea type="text">This is Text</textarea>
之后
<textarea type="text">This is My Text</textarea>
你可以试试这个。
$scope.text = $scope.insertText('This is Text', ' My', 7);
$scope.insertText = function(source, text, position) {
var subStr = source.substring(0, position);
return subStr + text + source.substring(subStr.length);
}
<textarea type="text">{{text}}</textarea>