JScript变量怪异

时间:2017-11-22 03:08:23

标签: function loops jscript

有人可以告诉我为什么从下面的服务器代码中打印出来的第3行并不是以“香蕉”字样开头的吗?相反,它返回一个空字符串。

var conn;

var g_itemid = 0;

var sql = "select 1 as indx, 'apple' as vtype, 'red' as vcolor, 'Mac' as vmisc  \
    union  \
    select 1 as indx, 'apple', 'green', 'Mayberry' \
    union  \
    select 2 as indx, 'banana', 'yellow', 'ripe' \
    union  \
    select 2 as indx, 'banana', 'green', 'not ripe'";   

if(connectToDatabase()==1) {

    qs=conn.execute(sql);

    while(!qs.eof) {          
        Response.Write(setItemText(qs("vtype"), qs("indx")) + "|" + qs("vcolor") + "|" + qs("vmisc")+ "<br>");
        qs.movenext();   
    }        

    conn.Close();
    conn = null;
}

function setItemText(item, itemid) {

    if(g_itemid!=itemid){
        g_itemid = itemid;
        return item;            
    }
    else {        
        return "";         
    }     
}

1 个答案:

答案 0 :(得分:0)

没关系,我需要使用parseInt设置全局。