Javascript语法问题——找到它

问题描述 投票:0回答:4

我有以下 javascript 片段,由于缺少 ; 而无法加载。在使用 searchUserInfo 声明 url 之前的声明之前。我已经双重和三次检查了此代码

function submitUserInfo(username) {

    url = "edit_user.php?cmd=submitinfo&username="+username+"&firstname="+document.userForm.firstname.value+"&lastname="+document.userForm.lastname.value+"&flaggedauctions="+document.userForm.flaggedauctions.value+"&lastauction="+document.userForm.lastauction.value+"&street1="+document.userForm.street1.value+"&city1="+document.userForm.city1.value+"&postcode1="+document.userForm.postcode1.value+"&street2="+document.userForm.street2.value+"&city2="+document.userForm.city2.value+"&postcode2="+document.userForm.postcode2.value+"&phone="+document.userForm.phone.value+"&mobilephone="+document.userForm.mobilephone.value+"&fax="+document.userForm.fax.value+"&email="+document.userForm.email.value+"&website="+document.userForm.website.value+"&bank="+document.userForm.bank.value+"&banknumber="+document.userForm.banknumber.value+"&accountnumber="+document.userForm.accountnumber.value+"&comments="+document.userForm.comments.value;

    var xmlHttp=GetXmlHttpObject(); //you have this defined elsewhere

    //if(xmlHttp.responseText == 'true') {

        xmlHttp.open("GET",url,true);

        xmlHttp.send(null);

        updateByUser(username);

    //}

}

function searchUserInfo() {

    url = "get_results.php?cmd=SearchUserData&searchstring="+document.searchForm.search.value"&subcat="+subcat;

    var xmlHttp=GetXmlHttpObject(); //you have this defined elsewhere

    //if(xmlHttp.responseText == 'true') {

        xmlHttp.open("GET",url,true);

        xmlHttp.send(null);

        update('Layer3', url);

    //}

}

我使用了 jslint,看不出有什么变化。没有错误。我正在使用 firebug,但它对我没有帮助。

javascript
4个回答
6
投票

您忘记了

+
运算符。这个:

url = "get_results.php?cmd=SearchUserData&searchstring="+document.searchForm.search.value"&subcat="+subcat;

应该是:

url = "get_results.php?cmd=SearchUserData&searchstring="+document.searchForm.search.value+"&subcat="+subcat;

3
投票

你在这里漏掉了一个+

value"&subcat="+subcat

2
投票

searchUserInfo,第一行,需要添加一个“+”

...document.searchForm.search.value +“&subcat=”...


1
投票

双重、三重、四重检查很好,但还不够。一次注释掉几行代码以查明有错误的行。

记住这句“计算机永远不会错”并习惯它。

例如

第一次测试:

/*
function blah(do){
   line 1
   line 2
   line 3
}
*/

然后:

function blah(do){
/*
   line 1
   line 2
   line 3
*/
}

然后:

function blah(do){

   line 1
   /*
   line 2
   line 3
   */

}

直到错误出现

© www.soinside.com 2019 - 2024. All rights reserved.