失踪 ;在声明对象变量之前

时间:2015-11-30 19:24:31

标签: javascript jquery syntax

我无法弄清楚为什么编译器在第一个变量声明之前抱怨缺少分号。 var convert {} 这与声明对象有关吗?

$(document).ready(function() { 
        var convert { 
            "one" : 1,
            "two" : 2,
            "three" : 3,
            "four" : 4,
            "five" : 5,
            "six" : 6, 
            "seven" : 7,
            "eight" : 8,
            "nine" : 9, 
            "ten" : 10,
            "eleven" : 11,
            "twelve" : 12,
            "thirteen" : 13,
            "fourteen" : 14, 
            "fifteen" : 15
        };

        $('.downloadfile').click(function() { 
            $id = this.id; 
            $numberstrings = ["one","two","three","four","five","six","seven","eight","nine","ten", "eleven", "twelve","thirteen","fourteen","fifteen"];
            $length = $numberstrings.length;
            for ($i=0; $i<$length; $i++){ 
                if ($id.indexOf($numberstrings[$i]) != -1)
                {
                    $id = $numberstrings[$i];
                }
            }

            $id = convert[$id];
            window.alert($id);
            $filename = 'p'+$id+'.mp3';
            $.ajax({ url: 'download.php?argument=$filename'});



        });

    });

2 个答案:

答案 0 :(得分:0)

简单的拼写错误:

var convert { 
         ^^^^^

缺少=

答案 1 :(得分:0)

您错过了Equal To运营商。

var convert = {};

希望它有所帮助!