开发者

Cannot get length in array

开发者 https://www.devze.com 2023-02-20 23:53 出处:网络
I could not even get the alert prompt. What wrong did I done on IE9? <script type=\"text/javascript\">

I could not even get the alert prompt. What wrong did I done on IE9?

<script type="text/javascript">
    var countrieslist=document.sc.s1
    var subjlist=document.sc.s2

    var subj=new Array()
    subj[0]=""
    subj[1]=["New York|newyorkvalue", "Los Angeles|loangelesvalue", "Chicago|chicagovalue", "Houston|houstonvalue", "Austin|austinvalue"]
    subj[2]=["Vancouver|vanc开发者_如何学Pythonouvervalue", "Tonronto|torontovalue", "Montreal|montrealvalue", "Calgary|calgaryvalue"]
    subj[3]=["London|londonvalue", "Glasgow|glasgowsvalue", "Manchester|manchestervalue", "Edinburgh|edinburghvalue", "Birmingham|birminghamvalue"]

function updateSubj(selectsubj) {
    if (selectsubj>0){
        for (i=0; i<subj[selectsubj].length; i++) {
        alert("ss");
            //s2.options[subjlist.options.length]=new Option(subj[selectsubj][i].split("|")[0], subj[selectsubj][i].split("|")[1])
        }
    }
}
</script>


I should check if it is an array.

function update (i) {
    if (subj[i] instanceof Array)
        for(var j in subj[i])
            alert(subj[i][j]);
    else
        alert(subj[i] || 'is undefined');
}

You can also check if it's an iterable by checking the length property

if (subj[i].length) // iterate list
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号