如何使用ng-click获取标签标签文本?

时间:2017-11-07 11:59:59

标签: javascript jquery html angularjs

我正在寻找一些解决方案,以便在点击时获取标签标签文字。我使用单选按钮进行多种选择。假设我单击本地选项卡按钮然后选择指向点单选按钮的指针。即时通讯获取单选按钮值,但我也需要类别名称(本地和外部)。

<ul class="tabs">
 <li class="tab-link current" data-tab="tabs-1">LOCAL</li>
 <li class="tab-link" data-tab="tabs-2">OUTSTATION</li>
</ul>
<div id="tabs-1" class="tab-content current">
                                    <div class="tab-elements">
                                        <div class="checkboxes-demo">
                                            <div class="fac fac-radio fac-default"><span></span>
                                                <input id="box1-fac-radio" type="radio" name="radioPlatFormName" ng-change="radioPlatForm('Point to Point')" value="Point to Point" ng-model="selectCar.platform">
                                                <label for="box1-fac-radio">Point to Point</label>
                                            </div>
                                            <div class="fac fac-radio fac-default"><span></span>
                                                <input id="box2-fac-radio" type="radio" name="radioPlatFormName" ng-change="radioPlatForm('Hourly')" value="Hourly" ng-model="selectCar.platform">
                                                <label for="box2-fac-radio">Hourly</label>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div id="tabs-2" class="tab-content">
                                    <div class="tab-elements">
                                        <div class="checkboxes-demo">
                                            <div class="fac fac-radio fac-default"><span></span>
                                                <input id="box3-fac-radio" type="radio" name="radioPlatFormName" ng-change="radioPlatForm('One Way')" value="One Way" ng-model="selectCar.platform">
                                                <label for="box3-fac-radio">One Way</label>
                                            </div>
                                            <div class="fac fac-radio fac-default"><span></span>
                                                <input id="box4-fac-radio" type="radio" name="radioPlatFormName" ng-change="radioPlatForm('Round Trip')" value="Round Trip" ng-model="selectCar.platform">
                                                <label for="box4-fac-radio">Round Trip</label>
                                            </div>
                                        </div>
                                    </div>
                                </div>

以下是获取单选按钮值的应用代码

    var appModule = angular.module('cormobApp', []);
appModule.controller('selectCarCtrl', function($scope) {
            $scope.radioPlatForm = function(platformChange) {
                $scope.platformSelected = platformChange;
            }

3 个答案:

答案 0 :(得分:0)

你可以这样做。

在HTML中

<li class="tab-link current" data-tab="tabs-1" ng-click="TabName('Local')">LOCAL</li>
 <li class="tab-link" data-tab="tabs-2" ng-click="TabName('Outstation')">OUTSTATION</li>

控制器内部

  $scope.TabName= function(name) {
           alert(name);// You can get selected tab name here
     }

答案 1 :(得分:0)

尝试这样做

on js

$scope.local = "LOCAL"
$scope.outstation = "OUTSTATION"

$scope.localfunction = function (local) {
$scope.platformSelected = local;
}

$scope.outstationfunction = function (outstation) {
$scope.platformSelected = outstation;
}

on html

 <li class="tab-link current" data-tab="tabs-1" ng-click="localfunction('local')">{{ local }}</li>
 <li class="tab-link" data-tab="tabs-2" ng-click="outstationfunction('outstation')>{{ outstation }}</li>

答案 2 :(得分:0)

<span class="third-text-right" ng-if="selectCar.platform == 'Hourly' || selectCar.platform == 'Point to Point'">Local</span>
 <span class="third-text-right" ng-if="selectCar.platform == 'One Way' || selectCar.platform == 'Round Trip'">Outstation</span>

我使用两个跨度来显示在单击任何子选项时选择了哪个选项卡,它将比较哪个单选按钮值与将显示该范围的条件匹配。

感谢您的回复。非常感谢