gpt4 book ai didi

javascript - 我想比较angularjs中输入文本框的旧值和新值是否相同?

转载 作者:行者123 更新时间:2023-11-30 09:51:45 25 4
gpt4 key购买 nike

我在 angularjs html 结构中有两个输入框。当我点击我的按钮或标签时,我想要我的文本框在 angularjs 中的旧值和新值,或者我想比较旧值和新值是否相同。我正在使用 Angular 1.4.7。

<input phone-input ng-show="mode == 'edit'" ng-model="leader.work"/>
<input phone-input ng-show="mode == 'edit'" ng-model="leader.mobile"/>

<a ng-show="mode == 'edit'" ng-click="mode = null;save_profile(leader)" style="cursor: pointer" title="Save">Save</a>

$scope.save_profile = function (leader) {
/* How to get/compare both text box old and new value are same or not*/
};

最佳答案

试试这个

function TodoCrtl($scope) {

$scope.newValue = 'Initial Text';
$scope.save_profile = function(newvalue, oldvalue) {

//Here you can access old value and new value from scope.
$scope.new = 'New Value :' + $scope.newValue;
$scope.old = 'Old Value :' + $scope.oldValue;

//After accessing update the scope old value to new value with function parameters
$scope.newValue = newvalue;
$scope.oldValue = newvalue;

};

$scope.changeValue = function() {

$scope.newValue = 'Dynamic Change';
};

}
<!DOCTYPE html>
<html ng-app>

<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<meta charset=utf-8 />
<title>ng-click</title>
</head>

<body>

<div ng-controller="TodoCrtl">

<input type=text ng-model="newValue" ng-init="oldValue=newValue">
<button ng-click="save_profile(newValue,oldValue)">Save</button>
<div>{{new}}</div>
<div>{{old}}</div>

<br>
<button ng-click="changeValue()">Change Dynamic</button>

</div>

</body>

</html>

关于javascript - 我想比较angularjs中输入文本框的旧值和新值是否相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36100084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com