The following two blocks are your problem, they both respond to a click on any li
(下面的两个块是你的问题,他们对任何一个点击皆响应li
)
$(document).on('click','li',function()
{
$('#studentname').val($(this).text());
$('#students').fadeOut();
});
$(document).on('click','li',function()
{
$('#groupname').val($(this).text());
$('#groups').fadeOut();
});
You need to adjust your selectors to target the respective lists as follows:(您需要按以下方式调整选择器以定位相应的列表:)
$(document).on('click','#students li',function()
{
$('#studentname').val($(this).text());
$('#students').fadeOut();
});
$(document).on('click','#groups li',function()
{
$('#groupname').val($(this).text());
$('#groups').fadeOut();
});
Or like this:(或像这样:)
$('#students').on('click','li',function()
{
$('#studentname').val($(this).text());
$('#students').fadeOut();
});
$('#groups').on('click','li',function()
{
$('#groupname').val($(this).text());
$('#groups').fadeOut();
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…