对不起,伙计们,仍然对 JQuery 很感兴趣。对创建这样的可选 ul li 列表有很大帮助
$(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;
});
});
但是,我怎样才能将所选 li 的值附加到文本字段中,以便它可以在表单中使用 - 由于 li 列表在表单之外,因此在这种情况下不能使用 Ajax 等。
此外,如果我在一个页面上说 3 或 4 个这些 ul li,我该如何包装上面的代码,使下一个 / 上一个按钮仅与它们适用的 ul li 一起工作。
提前致谢