2013-10-11 73 views
-2

在这下面的代码我得到所需的输出
EXTJS - 新手,开关箱的功能不能正常工作

fn: function(btn) { 
switch(btn){ 
case 'yes': 
Ext.Msg.prompt('Milton', 'Where is it?'); 
break; 
case 'no': 
Ext.Msg.alert('Milton', 
'Im going to burn the building down!'); 
break; 
case 'cancel': 
Ext.Msg.wait('Saving tables to disk...','File Copy'); 
break; 
} 
} 

这工作就好了。现在我试图在开关'yes'中做一个函数调用,但是我没有在屏幕上得到任何输出。
这是我正在使用的代码。

case 'yes': 
Ext.Msg.prompt('Milton', 'Where is it?', function(btn,txt) 
{ 
if (txt.toLowerCase() == 'the office') { 
Ext.get('my_id').dom.innerHTML = 'Dull Work'; 
}else{ 
Ext.get('my_id').dom.innerHTML = txt; 
} 
Ext.DomHelper.applyStyles('my_id',{ 
background: 'transparent 
url(images/stapler.png) 50% 50% no-repeat' 
}); 
}); 
break; 

在swich case'yes'中使用此代码,我得到一个空白屏幕。即使对话框消失了。请帮忙。

+0

什么是你在控制台得到错误控制台? –

+0

@LorenzMeyer感谢您的回复。我在控制台中没有收到任何错误。至少它应该显示对话框。但我所得到的只是一个空白的屏幕。 – SeasonalShot

回答

0

这是一个非常基本的JavaScript错误。一个字符串不能在该行的末尾延伸。这将工作。

case 'yes': 
Ext.Msg.prompt('Milton', 'Where is it?', function(btn,txt){ 
    if (txt.toLowerCase() == 'the office') { 
     Ext.get('my_id').dom.innerHTML = 'Dull Work'; 
    }else{ 
     Ext.get('my_id').dom.innerHTML = txt; 
    } 
    Ext.DomHelper.applyStyles('my_id',{ 
     background: 'transparent url(images/stapler.png) 50% 50% no-repeat' 
    }); 
}); 
break; 

在我得到了错误SyntaxError: Unexpected token ILLEGAL

+0

没有仍然没有工作.. – SeasonalShot

+0

再次:控制台中的错误是什么? (推荐:使用Chrome Devtools) –

+0

它适合我。您可能需要添加'console.log'来证明'Ext.Msg.prompt'确实被调用。 –