Javascript 如何根据条件切换最小和最大输入值?
我有两个Javascript 如何根据条件切换最小和最大输入值?,javascript,angularjs,html,input,Javascript,Angularjs,Html,Input,我有两个input元素,其中定义了min和max。 我如何反转这些值,最好是在HTML或JS(角度)中 例如: <label> Width: <input type="number" min="10" max="100"> </label> <label> Height: <input type="number" min="50" max="400"> </label> 宽度: 高度:
input
元素,其中定义了min和max。
我如何反转这些值,最好是在HTML或JS(角度)中
例如:
<label>
Width:
<input type="number" min="10" max="100">
</label>
<label>
Height:
<input type="number" min="50" max="400">
</label>
宽度:
高度:
如果用户在第一次输入中输入400,则第二次输入中的最小值和最大值将替换为min=“10”max=“100”
换句话说,值必须是可互换的。这里有一种方法来完成这项工作,使用一些额外的变量和
var myApp=angular.module('myApp',[]);
控制器('MyCtrl',['$scope',函数($scope){
$scope.minWidth=10;
$scope.maxWidth=100;
$scope.minHeight=50;
$scope.maxHeight=400;
$scope.update=函数(v){
if((v='w'&&$scope.width>$scope.maxWidth)| |(v='h'&&$scope.height>$scope.maxHeight)){
设reverseMax=$scope.maxWidth;
设reverseMin=$scope.minWidth;
$scope.maxWidth=$scope.maxHeight;
$scope.maxHeight=reverseemax;
$scope.minWidth=$scope.minHeight;
$scope.minHeight=reverseMin;
}
}
}]);代码>
宽度:
{{minWidth}}-{{maxWidth}
高度:
{{minHeight}}-{maxHeight}
您是否对此使用了任何类型的计算。如有,请邮寄