Javascript 添加到script.js的新函数会导致其他两个脚本无法工作

Javascript 添加到script.js的新函数会导致其他两个脚本无法工作,javascript,php,html,ajax,Javascript,Php,Html,Ajax,多亏了大家的帮助,这个项目终于开始了。多亏了大家的帮助,我学到了一些很酷的技能。尤其是Techstream和FormGet的人。使用Techstream的一些代码,我能够修改以适应我的同事正在使用的数据元素,这样他们可以添加文件夹名称,然后为每个文件夹名称分配描述符,或者他们可以在提交之前删除列表中的行并将其插入数据库。所以下一步是设计一个函数,这样当他们按下submit时,php脚本就会启动并将数组插入数据库。但是,当我将insertFunction放入script.js中时,会导致允许用户在

多亏了大家的帮助,这个项目终于开始了。多亏了大家的帮助,我学到了一些很酷的技能。尤其是Techstream和FormGet的人。使用Techstream的一些代码,我能够修改以适应我的同事正在使用的数据元素,这样他们可以添加文件夹名称,然后为每个文件夹名称分配描述符,或者他们可以在提交之前删除列表中的行并将其插入数据库。所以下一步是设计一个函数,这样当他们按下submit时,php脚本就会启动并将数组插入数据库。但是,当我将insertFunction放入script.js中时,会导致允许用户在表单中添加或删除行的其他两个函数无法工作。有人能看看这个,告诉我我做错了什么吗?我认为在同一个script.js文件中可以有多个函数。这是我的密码。显然,函数addRow和函数deleteRow允许用户从用户输入表单中添加或删除行。在我将第三个函数insertFunction添加到script.js之前,它们的工作非常有魅力。添加insertFunction时,它似乎禁用addRow和deleteRow。我似乎不明白我做错了什么。谢谢你的建议

function addRow(tableID) {/*this function allows the user to add more rows to the form to a maximum of 10000*/
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    if(rowCount < 10000){                           // limit the user from creating fields more than your limits
        var row = table.insertRow(rowCount);
        var colCount = table.rows[0].cells.length;
        for(var i=0; i<colCount; i++) {
            var newcell = row.insertCell(i);
            newcell.innerHTML = table.rows[0].cells[i].innerHTML;
        }
    }else{
        alert("Contact Records Management if you have more than 10000 records.");

    }
}

function deleteRow(tableID) { /*this function allows the user to delete rows from the form but requires they have at least 1 row*/
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    for(var i=0; i<rowCount; i++) {
        var row = table.rows[i];
        var chkbox = row.cells[0].childNodes[0];
        if(null != chkbox && true == chkbox.checked) {
            if(rowCount <= 1) {                         // limit the user from removing all the fields
                alert("You must have at least 1 folder.");
                break;
            }
            table.deleteRow(i);
            rowCount--;
            i--;
        }
    }
}

function insertFunction() { /*This is the function that takes the user input from the form, validates and sends to filedetailinsert.php for insert into db*/

var officecode = document.getElementById("officecode").value;
var myusername = document.getElementById("myusername").value;
var day = document.getElementById("day").value;
var month = document.getElementById("month").value;
var year = document.getElementById("year").value;
var creator = document.getElementById("creator").value;
var officechief = document.getElementById("officechief").value;
var status = document.getElementById("status").value;
var BX_NAME = document.getElementById("BX_NAME").value;
var BX_fileseries = document.getElementById("BX_fileseries").value;
var BX_classification = document.getElementById("BX_classification").value;
var BX_media = document.getElementById("BX_media").value;

/*Returns successful data submission message when the entered data is inserted into database */

var dataString = 'officecode1=' +officecode+ 'myusername1=' +myusername+ 'day1=' +day+ 'month1=' +month+ 'year1=' +year+ 'creator1=' +creator+ 'officechief1=' +officechief+ 'status1=' +status+ 'BX_NAME1=' +BX_NAME+ 'BX_fileseries1=' +BX_fileseries 'BX_classification1=' +BX_classification+ 'BX_media1=' +BX_media;

if 

(officecode == '' || myusername == '' || day == '' || month == '' || year == '' || creator == '' || officechief == '' || status == '' || BX_NAME == '' || BX_fileseries == '' || BX_classification == '' || BX_media == '') 

{
/*the statement above checks to see if all fields are populated.  If there are empty fields it displays a message "Please Complete All Fields" and will not proceed to the $.ajax action below.  When the user clicks ok on the error message they remain at the user input form to populate the field(s) they left blank.  If all fields are populated then the $.ajax action fires, invoking filedetailinsert.php script to place the data into the database.*/


alert(Please Complete All Fields");


} 

else 

{
//AJAX code to submit form comes next

$.ajax(

{
    type: "POST",
url: "filedetailinsert.php",
    data: dataString,
    cache: false,
    success: function(html) 

    {
        alert(hmtl);
    }

} 

);

}


return false;



}
消息开头缺少双引号

应该是:

alert("Please Complete All Fields");

注意:请填写所有字段;缺少如上所述的起始报价。这是显而易见的,因为如此语法高亮。我强烈建议使用与此相同的代码编辑器。另外,在浏览器中使用JS控制台,它会突出显示错误,但是一个函数中的语法错误会导致前两个函数停止工作吗?正如我上面所问的,一个函数中的语法错误会导致前两个函数停止工作吗?好吧!我会纠正错误,看看会发生什么!非常感谢大家的帮助!是的……这就解决了问题!感谢lolka_bolka、Steve和user887675对您的帮助!
alert("Please Complete All Fields");