Cofirm box在javascript验证中不起作用

Cofirm box在javascript验证中不起作用,javascript,Javascript,我正在处理一个带有java脚本验证的表单。我的验证有问题。确认框在特定实例中不起作用。我的代码是 if((frm_update_announcement.sublink[0].checked == true)) { if((document.getElementById('captionurl').value.trim()=="") && document.getElementById("captionfile").files.length == 0 ) ) {

我正在处理一个带有java脚本验证的表单。我的验证有问题。确认框在特定实例中不起作用。我的代码是

if((frm_update_announcement.sublink[0].checked == true)) {
    if((document.getElementById('captionurl').value.trim()=="") && document.getElementById("captionfile").files.length == 0 ) ) {   
        if (document.getElementById('olddocument').value.trim()=="") {
            alert("Enter a url/upload a file");
            document.getElementById('captionurl').focus();
            return false;
        }
    }
}
if((frm_update_announcement.sublink[1].checked == true)) {
    for (var i = 1; i <= n; i++) {
        if (document.getElementById('attachment_caption' + i).value.trim()!="") {
            if ((document.getElementById('url'+i).value.trim()=="") && (document.getElementById("document"+i).files.length == 0 ) ) {
                alert("Add url/file with caption");
                document.getElementById('url'+i).focus();
                return false;   
            }                             
        }
    }         
}
if(confirm("Do you want to update the announcement") == true) {
    return true;
} else {
    return false;
}
if((frm\u update\u announcement.sublink[0]。选中==true)){
如果((document.getElementById('captionurl').value.trim()==“”)和&document.getElementById(“captionfile”).files.length==0)){
if(document.getElementById('olddocument').value.trim()=“”){
警报(“输入url/上载文件”);
document.getElementById('captionurl').focus();
返回false;
}
}
}
if((frm\u update\u announcement.sublink[1]。选中==true)){
对于(var i=1;i>添加新的子链接

您的第一个if语句中有语法错误

 if ( ( frm_update_announcement.sublink[0].checked == true )){
        if ((document.getElementById('captionurl').value.trim()=="" )  && (document.getElementById("captionfile").files.length == 0) )
            {  
                if (document.getElementById('olddocument').value.trim()=="")
                 {
                    alert("Enter a url/upload a file");
                    document.getElementById('captionurl').focus();
                    return false;
                }
             }

}
用第一个if语句替换以下代码

 if ( ( frm_update_announcement.sublink[0].checked == true )){
        if ((document.getElementById('captionurl').value.trim()=="" )  && (document.getElementById("captionfile").files.length == 0) )
            {  
                if (document.getElementById('olddocument').value.trim()=="")
                 {
                    alert("Enter a url/upload a file");
                    document.getElementById('captionurl').focus();
                    return false;
                }
             }

}

希望这对您有用。

if(确认(“您想更新公告”)
@Azola它不起作用我的问题是if((frm\u update\u announcement.sublink[1]。checked==true))。如果我删除该条件,它工作正常这是什么
frm\u update\u announcement.sublink[1].checked
谢谢不起作用..我在条件中有错误((frm_update_announcement.sublink[1].checked==true))对不起..什么也没发生..我发现问题出在if((document.getElementById('url'+I).value.trim()==“”)和&(document.getElementById(“document”+I.files.length==0))
 if ( ( frm_update_announcement.sublink[0].checked == true )){
        if ((document.getElementById('captionurl').value.trim()=="" )  && (document.getElementById("captionfile").files.length == 0) )
            {  
                if (document.getElementById('olddocument').value.trim()=="")
                 {
                    alert("Enter a url/upload a file");
                    document.getElementById('captionurl').focus();
                    return false;
                }
             }

}