2016-11-04 27 views
0

我不知道爲什麼在IE瀏覽器,代碼報告錯誤。下面是代碼:IE瀏覽器拋出錯誤,如果語句

if ($size === null) { 
    $sizeFolder = '48x48'; 
} else $sizeFolder = $size+'x'+$size; 

的錯誤如下:

SCRIPTING1006: ')' expected 

IE將設置一個)這裏是這樣的:

if ($size === null)) { 
    $sizeFolder = '48x48'; 
} else $sizeFolder = $size+'x'+$size; 

但這仍無法正常工作。爲什麼IE報告錯誤?

這裏是完整的代碼:

$.ttMessageBox.getIcon = function ($icon,$size=null) { 
    var $_icons = Array('[Information]','[Error]','[Question]','[OK]'); 
    if ($size === null) { 
    $sizeFolder = '48x48'; 
    } else $sizeFolder = $size+'x'+$size; 
    $result = ''; 
    $Icon = $_icons.indexOf($icon); 
    switch ($Icon) { 
    case 0: $result += '<img src="/img/icons/'+$sizeFolder+'/dialog_information.png" />'; 
       break; 
    case 1: $result += '<img src="/img/icons/'+$sizeFolder+'/dialog_error.png" />'; 
       break; 
    case 2: $result += '<img src="/img/icons/'+$sizeFolder+'/dialog_question.png" />'; 
       break; 
    case 3: $result += '<img src="/img/icons/'+$sizeFolder+'/dialog_check.png" />'; 
       break; 
    default: $result += ''; 
    } 
return $result; 
} 
+1

它可期待各地else語句括號。 –

+4

您的錯誤是在代碼之前的腳本中的其他地方,因爲這工作得很好,語法是有效的。請發佈整個腳本文件。 – plalx

+0

如果if($ size === null)){',try - >'if($ size === null){' – Keith

回答

0

這是現在的工作代碼:

$.ttMessageBox.getIcon = function ($icon,$size) { 
    var $_icons = Array('[Information]','[Error]','[Question]','[OK]'); 
    if (typeof $size === "undefined") { 
    $sizeFolder = '48x48'; 
    } else $sizeFolder = $size+'x'+$size; 

感謝@Luke伍德沃德

0

的錯誤是在這條線:

$.ttMessageBox.getIcon = function ($icon,$size=null) { 

IE不會對功能參數支持默認值。您不能擁有=null位。

相關問題