我正在尝试勾选一个复选框以选择一个,多个或全部,并在用户点击“打印我”按钮时将其发送给我们。我迷失在这一个,有没有人做过类似的事情,我可以看到它是如何做的正确的?这是我的问题的测试代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Select and Print</title>
<script src="/jquery-1.11.min.js"></script>
<script>
$(document).ready(function() {
$('#selecctall').click(function(event) {
if(this.checked) {
$('.checkbox1').each(function() {
this.checked = true; // select all checkboxes with class "checkbox1"
printDoc(docUrl);
});
}else{
$('.checkbox1').each(function() {
this.checked = false; // deselect all checkboxes with class "checkbox1"
});
}
});
});
function printDoc(gotUrl) {
var doc = window.open(gotUrl);
doc.print();
doc.close();
}
</script>
</head>
<body><form action="doit.pl" method="post">
</br>
<input type="checkbox" id="selecctall"/> Select All
<input class="checkbox1" type="checkbox" name="check[]" value="names.html"></br>
<input class="checkbox1" type="checkbox" name="check[]" value="copy.html"></br>
<input class="checkbox1" type="checkbox" name="check[]" value="card.html"></br>
<input class="checkbox1" type="checkbox" name="check[]" value="page.html"></br>
<input class="checkbox1" type="checkbox" name="check[]" value="test.html"></br>
<input type="submit" name="print me"></br>
</body></form>
</html>
感谢您的帮助!