【问题标题】:How to get checkbox data in textarea and textarea data in scope?如何获取文本区域中的复选框数据和范围内的文本区域数据?
【发布时间】:2019-11-23 15:31:55
【问题描述】:

我想要 textarea 中的复选框数据并使用范围获取段落中的 textarea 数据。我想在 textarea 中获取复选框数据并编辑数据并在 {{newer}} 中获取 textarea 数据。

我已经使用复选框范围在 textarea 中添加了复选框值,类似地在段落中添加了 textarea 范围

<div ng-app="myApp">

<input ng-model="er1" type="checkbox" ng-true-value="'10th / '" ng-false-value="">10th
<input ng-model="er2" type="checkbox" ng-true-value="'12th / '" ng-false-value="">12th
<input ng-model="er3" type="checkbox" ng-true-value="'B.Ed / '" ng-false-value="">bed

<textarea ng-model="newer">{{er1}}{{er2}}{{er3}}</textarea>

<p>{{newer}}</p>

</div>
var app = angular.module('myApp', []);
app.controller(function($scope) {

});

【问题讨论】:

    标签: javascript html angularjs forms


    【解决方案1】:

    使用ng-change 指令:

    <input ng-model="er1" type="checkbox" ng-change="updateTextArea()"
           ng-true-value="'10th / '" ng-false-value="">10th
    <input ng-model="er2" type="checkbox" ng-change="updateTextArea()"
           ng-true-value="'12th / '" ng-false-value="">12th
    <input ng-model="er3" type="checkbox"  ng-change="updateTextArea()"
           ng-true-value="'B.Ed / '" ng-false-value="">bed
    
    <textarea ng-model="newer">{{er1}}{{er2}}{{er3}}</textarea>
    
    <p>{{newer}}</p>
    
    app.controller(function($scope) {
        $scope.updateTextArea = function() {
            $scope.newer = $scope.er1 + $scope.er2 + $scope.er3;
        };
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 2013-04-08
      相关资源
      最近更新 更多