对不起,在JQuery上仍然很胖。有很大的帮助,创建一个可选择的UI李名单这样JQuery将文本附加到文本字段
$(document).ready(function(){
$('.selectoption li').not(':first').hide();
$('.prev, .next').click(function() {
// Determine the direction
var dir = $(this).hasClass('prev') ? 'prev' : 'next';
// Get the li that is currently visible
var current = $('.selectoption li:visible');
// Get the element that should be shown next according to direction
var next = dir == 'prev' ? current.prev('li') : current.next('li');
// If there's no more in that direction, select first/last
if(next.size() == 0) {
next = dir == 'prev' ? $('.selectoption li:first') : $('.selectoption li:first');
}
// Hide them all..
$('.selectoption li').hide();
// And show the new one
next.show();
return false;
});
});
但我怎么能那么选择里的值添加到一个文本字段,以便它可以在表单中使用 - 不能在此使用Ajax等。因为李列表不在表单中。
另外,如果我在页面上说出了3个或4个这样的ul li,我如何用上面的代码包装上一个代码,使得下一个/ prev按钮只能使用它们适用的ul li。
在此先感谢