jquery.ui.spinner 变化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5149830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery.ui.spinner change
提问by etriad
I'm trying to use the latest version of the jquery.ui.spinner.js . http://wiki.jqueryui.com/w/page/12138077/Spinner
我正在尝试使用最新版本的 jquery.ui.spinner.js 。http://wiki.jqueryui.com/w/page/12138077/Spinner
The spinners are showing-up and updating the textboxes, but I'm having trouble figuring out how to capture the 'change' event. It triggers when you manually change the value in the textbox, but not when you use the spinner arrows.
微调器正在显示并更新文本框,但我无法弄清楚如何捕获“更改”事件。它在您手动更改文本框中的值时触发,但在您使用微调箭头时不会触发。
jquery:
查询:
$('input[name*="opening"]').spinner({ min: 0, max: 100});
$('#doorsize6w7h-f').spinner().change(function(){
alert($(this).spinner('value'));
});
html:
html:
<input type="text" value="0" class="front" id="doorsize6w7h-f" name="opening[0][0]" />
回答by alex
回答by Pablo S G Pacheco
I think this is what you need:
我认为这就是你需要的:
$('.mySpinner').spinner({
stop:function(e,ui){
alert('Triggered after a spin.');
}
});
Unlike binding to the click
event of the buttons, this will also detect use of the up/down keys on the keyboard.
与绑定到click
按钮的事件不同,这还将检测键盘上向上/向下键的使用。
See this page for details and more events: http://api.jqueryui.com/spinner/#entry-examples
有关详细信息和更多事件,请参阅此页面:http: //api.jqueryui.com/spinner/#entry-examples
回答by Arman Bimatov
There is no "change" event, instead use "spinstop" event:
没有“change”事件,而是使用“spinstop”事件:
$('#doorsize6w7h-f').on("spinstop", function(){
alert($(this).spinner('value'));
});
The documentation also suggests spinchangeevent, but it's kind of laggy for me.
文档还建议了spinchange事件,但对我来说有点滞后。
资源:http: //api.jqueryui.com/spinner/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DUI%2FSpinner%2Fspinner%26redirect%3Dno#event-change
回答by George Mavritsakis
Well, actually I would route changes through standard 'change' event and capture everything, like that:
好吧,实际上我会通过标准的“更改”事件路由更改并捕获所有内容,如下所示:
$('input[name*="opening"]').spinner({
min: 0,
max: 100,
spin: function(event, ui) {
$(this).change();
}
});
回答by mm201
This is giving me the most fluid results:
这给了我最流畅的结果:
function betterSpinner(input)
{
input.spinner(
{
spin: function(event, ui)
{
// the spin event is raised before the value actually gets changed,
// so let's update it here before raising the input's change() event.
input.val(ui.value);
input.change();
}
});
}
$(document).ready(function ()
{
betterSpinner($("#myInput"));
});
回答by goFrendiAsgard
I know this question has already been answered. But I hope this will help others.
我知道这个问题已经有人回答了。但我希望这会对其他人有所帮助。
Beside manually edit the value and using the spinner's arrow button, one can also edit the value of spinner by using arrow button on keyboard. In this case, I find keyup event is more robust than change event:
除了手动编辑值和使用微调器的箭头按钮外,还可以使用键盘上的箭头按钮编辑微调器的值。在这种情况下,我发现 keyup 事件比 change 事件更强大:
$(document).ready(function(){
var range_spinner = $('.spinner').spinner();
// hack to trigger input keyup whenever spinner button clicked:
$('.ui-spinner-button').click(function() { $(this).siblings('input').keyup(); });
// keyup will catch any stroke on keyboard
$('#range').keyup(function(){
console.log(range_spinner.spinner('value'));
});
});