Closed. This question needs details or clarity. It is not currently accepting answers. Learn more
想改进这个问题吗?添加细节并通过editing this post澄清问题。
5年前关闭。
您好,我想创建加减按钮来更改此HTML的范围值:
<label for="points">Width:</label>

<input type="range" name="amountRange" id="points" value="100" min="10" max="100" step="1" oninput="this.form.amountInput.value=this.value" />
<input type="text" name="amountInput" id="textnumber" min="10" max="100" step="1" value="100" oninput="this.form.amountRange.value=this.value" /><span>%</span>
<input type="button" id="plus" value="+" />
<input type="button" id="minus" value="-" />

我试过了
var counter = document.getElementById("points").value;
$(document).ready(function () {
        $('#minus').click(function () {
            counter++;
        });
        $('#points').change(function () {
            $('#navi').css({
                width: this.value + '%'
            });
        });

最佳答案

这里有一个解决方案,一切正常:
http://jsfiddle.net/kgLsky8s/2/

var counter = document.getElementById("points").value;

$(document).ready(function () {

    $("#plus").click(function(){

        var newValuePlus = parseInt($("#textnumber").val()) + 1;
        if ( newValuePlus > 100 ) return;

        $("#points, #textnumber").val(newValuePlus);

    });


    $("#minus").click(function(){

        var newValueMinus = parseInt($("#textnumber").val()) - 1;
        if ( newValueMinus < 0 ) return;

        $("#points, #textnumber").val(newValueMinus);
    });

    $("#points").change(function(){

        var newValue = $(this).val();
        $("#textnumber").val(newValue);

    });

    $("#textnumber").change(function(){

        var newValue = $(this).val();
        $("#points").val(newValue);

    });

});

关于jquery - jQuery的加减按钮,用于更改div宽度的范围,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26260404/

10-09 15:43