$('input[name="accounts"]').on('click', function() { $('input[name="accounts"]:checked').each(function() { if (index == 0) { txt = $(this).val(); $("#accounts-text").html(txt); } else { $("#accounts-text").append(txt); } }); });
Accounts Gmail Facebook Instagram Accounts:
在上面的代码中,帮助我在尝试在同一页面中选择显示复选框值时找出错误.
您可以使用map()和get()获取所有值.这将返回所有已检查值的数组.使用join()该数组转换成字符串.
map()
get()
join()
$('input[name="accounts"]').on('click', function() { var result = $('input[name="accounts"]:checked').map(function() { return this.value; }).get(); $("#accounts-text").html(result.join("")); });