如何在一个数字处停止HTML5范围输入?

时间:2015-03-26 15:19:13

标签: javascript angularjs html5 html-input

我使用angularjs来阻止范围滑块为75,但这不是一个好方法。有人可以指导我怎么做吗? [编辑在max = 75回答后澄清]记住我确实要显示总计100或最大比例但仍希望限制为75%或75。

<html ng-app="root">
<body>
    <div ng-controller="index">{{message}}
        <input type=range ng-model="data.sl" id=sl />
        <input type=text ng-model="data.sl" />
    </div>
</body>
</html>
<script src="angular.js"></script>

angular.module('root', [])
.controller("index", ["$scope", function ($scope) {
    $scope.message = "Hello World!";
    $scope.data = {};
    $scope.data.sl = 12;
    $scope.$watch('data.sl',function(nv,ov){
        if(nv==ov)return;

        if(nv >= 75){
            document.getElementById("sl").stepDown(10);
            console.log("going up");
        }
    });
}]);

2 个答案:

答案 0 :(得分:1)

只需使用max属性来限制范围输入的最大值。像这样:

<input type="range" value="0" max="75">

有关详细信息,请查看MDN的文档about the input element

答案 1 :(得分:0)

我走了:

    $scope.$watch('data.sl',function(nv,ov){
    if(nv==ov)return;

    if(nv >= 75){
        //document.getElementById("sl").stepDown(10);
        $scope.data.sl=75;
        console.log("going up");
    }
    if(nv <= 25){
        //document.getElementById("sl").stepDown(10);
        $scope.data.sl=25;
        console.log("going down");
    }
});