30

jquery と hmtl5 の範囲に少し問題があります。変更された値を取得しようとしていますが、イベントリスナーはそれをキャプチャしていません。現在、私のコードは次のとおりです。

HTML

html += '<li>Apply Credits: <input type="range"  min="0" max="'+credits+'" name="discount_credits" id="discount_credits" /> <span>'+credits+'</span></li>'

そして、JSは次のとおりです。

$('#discount_credits').mousewheel( function() { 
        alert('it changed!'); 
        alert('new value = ' + $(this).val()); 
    });

私も試してみました

$('#discount_credits').change( function() { 
            alert('it changed!'); 
            alert('new value = ' + $(this).val()); 
        });

どちらも機能していないようです。私は何か間違ったことをしていますか?

4

5 に答える 5

41
$('input[type=range]').on('input', function () {
    $(this).trigger('change');
});

これによりchange、すべてのinputイベントでイベントが発生します。

于 2015-03-13T18:32:28.893 に答える
18

<input type="range">を使用した HTML5 では問題ないようですchange

参照: http://jsfiddle.net/DerekL/BaEar/33/

于 2012-05-06T20:01:32.117 に答える
3

on change イベントは私にとっては正しく機能しているようです: http://jsfiddle.net/zV3xD/7/

<input type="range"  min="0" max="100" name="discount_credits" id="discount_credits" />

<span id="newValue" value="0">0</span>

$('#discount_credits').change( function() {
    var newValue = this.value;        
    $('#newValue').html(newValue);
});​

または、次のようなことを試すことができます

<form oninput="result.value=parseInt(a.value)">
    <input type="range" name="a" value="50" /> =
    <output name="result">0</output>
</form>

outputここの例を使用: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/output

于 2012-05-06T19:55:07.583 に答える