<div class ="container" ng-show="mbrscemployee=='yes'">
<span class="btn">click<span>
</div>
<button class="submit">submit</button>
当有人按button
标记时,会检查ng-show
是否为true
,然后会自动点击span
。
答案 0 :(得分:1)
只需检查ngShow
使用的条件:
<div class ="container" ng-show="mbrscemployee=='yes'">
<span class="btn">click<span>
</div>
<button ng-click="foo()" class="submit">submit</button>
控制器:
$scope.foo = function() {
if ($scope.mbrscemployee == 'yes') {
}
}
答案 1 :(得分:1)
如果您希望在span
元素上触发点击事件,则点击button
后,当ng-show
为真时:
DOM:
<div class="container" ng-show="mbrscemployee=='yes'">
<span id="myspan" class="btn">click<span>
</div>
<button ng-click="btnClick()" class="submit">submit</button>
控制器:
$scope.btnClick = function() {
if ($scope.mbrscemployee == 'yes') {
angular.element('#myspan').triggerHandler('click');
}
}
编辑:虽然,以下方法更有意义:
DOM
<div class="container" ng-show="mbrscemployee=='yes'">
<span ng-click="spanClick()" id="myspan" class="btn">click<span>
</div>
<button ng-click="btnClick()" class="submit">submit</button>
控制器:
$scope.spanClick = function() {
// do something
}
$scope.btnClick = function() {
if ($scope.mbrscemployee == 'yes') {
$scope.spanClick();
}
}
答案 2 :(得分:0)
你可以写ng-click =&#34; someFunction&#34;在提交按钮,它将检查您的变量$ scope.mbrscemployee是否为真,然后您可以从那里调用后续函数。!