嘿,在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());
});
两种方法似乎都不管用。我做错了什么吗?
发布于 2015-03-14 02:32:29
$('input[type=range]').on('input', function () {
$(this).trigger('change');
});
这将在每个input
事件上触发change
事件。
发布于 2012-05-07 04:01:32
在使用change
的HTML5 <input type="range">
上似乎没有任何问题。
发布于 2013-11-18 12:14:21
我假设您的跨度有一个id:<span id="slidernumber">...</span>
还假设您有一些滑块,并且您希望在移动其中任何一个滑块时看到文本更改:
<li>
Apply Credits1:
<input type="range" min="0" max="100"
name="discount_credits1" id="discount_credits"
/>
</li>
<li>
Apply Credits2:
<input type="range" min="0" max="100"
name="discount_credits2" id="discount_credits"
/>
</li>
<span id="slidernumber">50</span>
试试这个:
$(document).ready(function(){
$("[type=range]").change(function(){
var newval=$(this).val();
$("#slidernumber").text(newval);
});
});
http://jsfiddle.net/MahshidZeinaly/CgQ5c/
现在让我们假设您有几个滑块,但是您希望看到如果其中一个特定的滑块被移动,文本会发生变化。(我假定它是这样的,因为range输入在li标记中,并且您给它起了一个名字):
<li>
Apply Credits1:
<input type="range" min="0" max="100"
name="discount_credits1" id="discount_credits"
/>
<span id="slidernumber">50</span>
</li>
<li>
Apply Credits2:
<input type="range" min="0" max="100"
name="discount_credits2" id="discount_credits"
/>
<span id="slidernumber">50</span>
</li>
试试这个:
$(document).ready(function(){
$("[type=range]").change(function(){
var newv=$(this).val();
$(this).next().text(newv);
});
});
https://stackoverflow.com/questions/10473554
复制相似问题