我使用一个简单的JavaScript函数来选择所有复选框,但是他们不输出他们应该输出的内容,即输出电子邮件。这是用于输出电子邮件的JavaScript和用于检查所有复选框的JavaScript: 用于输出电子邮件的JavaScript:
function emailNextWithAddress(chk,address)
{
var nextEmail, inside_where;
if(chk.checked === true)
{
nextEmail = document.createElement('input');
nextEmail.id = address;
nextEmail.value = address;
nextEmail.type = 'text';
nextEmail.name = 'email[]';
nextEmail.className = 'insemail';
nextEmail.style.display = 'inline-block';
inside_where = document.getElementById('addEmail');
inside_where.appendChild(nextEmail);
}
else
{
inside_where = document.getElementById(address);
inside_where.parentNode.removeChild(inside_where);
}
}
JavaScript检查所有复选框:
function toggle(chk) {
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i] != chk)
checkboxes[i].checked = chk.checked;
}
}
以下是所请求的HTML,选中所有的复选框(使用&#39; \&#34;&#39;因为我使用的是php):
echo "Selecionar todos: <input type=\"checkbox\" onclick=\"toggle(this);\"/>"
而while函数:
while($infoItems = $result->fetch_array()){
echo "
<div class = \"scroll\">
<form method=\"GET\" id=\"\"></form>
<table class =\"table\" id=\"table\">
<tbody>
<tr>
<td><input type=\"checkbox\" ".($infoItems['Enviado']?' checked':' ')." onclick=\"emailNextWithAddress(this, '".$infoItems['EmailGeral']."');\"/></td>
</tr>
</tbody>
</table>
</div>";
}