Javascript 隐藏成功消息
我将以下代码显示为记录的成功更新。用户仍保持在同一编辑部分&请参见Javascript 隐藏成功消息,javascript,angularjs,Javascript,Angularjs,我将以下代码显示为记录的成功更新。用户仍保持在同一编辑部分&请参见更新按钮上方的thismsg 我希望这个msg消失,因为用户仍然可以编辑记录 如何隐藏此成功消息 <div class="label label-success" data-ng-show="updateStatus"> <span class="glyphicon glyphicon-thumbs-up icon-white"></span>updated! </div>
更新按钮上方的thismsg
我希望这个msg
消失,因为用户仍然可以编辑记录
如何隐藏此成功消息
<div class="label label-success" data-ng-show="updateStatus">
<span class="glyphicon glyphicon-thumbs-up icon-white"></span>updated!
</div>
更新!
只有当您将$scope.updateStatus
设置为true
--所以在AJAX之后,不要将此标志设置为true
--将其保留为false
,您的消息将永远不会显示。只需在添加成功消息后添加此标志即可
setTimeout(function(){$('.label-success').slideUp();},3000); //slidup after 3 second
上面的代码将在3秒钟后滑出消息
<div class="col-sm-6 form-group">
<label for="text">Text</label>
<input class="form-control input-lg" type="text" id="text" required name="text" ng-model="user.text" **ng-change="OnChange()"** placeholder="Enter your text">
</select>
</div>
<div class="col-sm-6 form-group">
<label for="email">Email Address</label>
<input class="form-control input-lg" type="email" id="email" required name="email" ng-model="user.email" **ng-change="OnChange()"** placeholder="Enter your email">
</div>
对所有字段调用此ng change=“OnChange()”
或者尝试此警报标记。您可以在不需要的时间内删除警报
<div ng-controller="AlertDemoCtrl">
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>
<button class='btn btn-default' ng-click="addAlert()">Add Alert</button>
</div>
演示:只需将falsy值分配给updateStatus范围变量。将该值分配到何处?是否要在超时后隐藏消息(setTimeout())或者如果用户编辑了某个内容?任何人都会执行@CrisimIlNumenoreanoworks…但这只是第一次…因此,如果用户再次编辑某个内容,msg
不会显示…为成功消息div创建一个id,然后将该id用于slideup函数,对于不同的消息div,id应该不同。更简单的方法是在html中使用successdiv
,而不是通过ajax,然后使用slideDown()显示消息,上面的代码在3秒钟后隐藏消息,这样每个成功消息都会显示相同的div
<div ng-controller="AlertDemoCtrl">
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>
<button class='btn btn-default' ng-click="addAlert()">Add Alert</button>
</div>
function AlertDemoCtrl($scope) {
$scope.alerts = [
{ type: 'danger', msg: 'Oh snap! Change a few things up and try submitting again.' },
{ type: 'success', msg: 'Well done! You successfully read this important alert message.' }
];
$scope.addAlert = function() {
$scope.alerts.push({msg: "Another alert!"});
};
$scope.closeAlert = function(index) {
$scope.alerts.splice(index, 1);
};
}