复选框验证后如何停止请求过程?如果复选框从未选择过,我想停止请求。即使成功验证未选中复选框,以下脚本也不会停止该过程。
function addNewItem(id) {
var i, chks = document.getElementsByName('itemCheckbox');
for (i = 0; i < chks.length; i++){
if (chks[i].checked){
return true;
}else{
alert('No item selected');
return false;
}
}else{
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("itemTable").innerHTML=xmlhttp.responseText;
initPlayWidget();
}
}
var itemCheckbox = document.forgetMeNotForm.itemCheckbox;
var selectedSong = "";
if (typeof itemCheckbox.length === 'undefined') {
if (itemCheckbox.checked == true) {
selectedSong = itemCheckbox.value + ",";
}
} else {
for (var i=0; i < itemCheckbox.length; i++) {
if (itemCheckbox[i].checked) {
selectedItm = selectedItm + itemCheckbox[i].value + ",";
}
}
}
var type = document.getElementById("typeDropdown").value;
var monthValue = document.getElementById("monthDropdown").value;
var dayValue = document.getElementById("dayDropdown").value;
var startTime = document.getElementById("hrDropdown1").value + document.getElementById("minDropdown1").value;
var endTime = document.getElementById("hrDropdown2").value + document.getElementById("minDropdown2").value;
var itmId = document.getElementById("itmNumber").value;
xmlhttp.open("POST","/sites/" + domainName + "/themes/web/common/myLib.php" ,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("action=addItemRule&id="+id+"&selectedItm=" + selectedItm + "&type=" + type + "&monthValue=" + monthValue
+ "&dayValue=" + dayValue + "&startTime=" + startTime + "&endTime=" + endTime + "&itmId=" + itmId);
}
}
谢谢。