Jquery在列表框中获得前面选定的值 [英] Jquery get the pervious selected value in listbox
本文介绍了Jquery在列表框中获得前面选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含10个元素的列表框。现在选择元素5。如果我将值更改为8,那么我需要同时获得5和8.
I have a list box with 10 elements. now the element 5 is selected. If i change the value to 8 then i need to get both 5 and 8.
即我需要当前选定的项目和上一个选定的项目。
i.e I need the currently selected item and previous selected item.
在Jquery中是否有可能?请只做那些需要的。谢谢
Is there any possibility in Jquery. Please do the needful. Thanks
推荐答案
试试这个:
Try this:
// on load
$("#mySelect").data("previous-value", $("#mySelect").val());
// on change
$("#mySelect").change(function() {
var previousValue = $(this).data("previous-value");
// do things with the previous value
// update previous value
$(this).data("previous-value", $(this).val());
});
这篇关于Jquery在列表框中获得前面选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文