2012-07-21 88 views
0

代碼片段:

var role=s[0].Role;// role contains string value 
dijit.byId("editRole").attr("Value",getRoleByName(role)); 

function getRoleByName(role) 
{ 
    var roleVal; 
    alert(role); 
    switch(role) 
    { 
     case 'Basic User' :roleVal='1';break; 
     case 'Network Operator' :roleVal='3';break; 
     case 'System Administrator' :roleVal='5';break; 
     case 'Custom Level 1' :roleVal='11';break; 
     case 'Custom Level 2' : roleVal='12';break; 
     default: roleVal='1';break; 
    } 
    return roleVal; 
} 

當我試着打電話給其在它的switch語句,我在IE8中得到以下錯誤的JavaScript方法,但在FF工作正常..開關的情況下沒有在IE8工作

錯誤在開發工具:

method Error executing: function(/*Event*/ e){ 
    // summary: 
    // Handler when the user activates the button portion. 
    if(this._onClick(e) === false){ // returning nothing is same as true 
     e.preventDefault(); // needed for checkbox 
    } else if (this.type == "submit" && !this.focusNode.form){ // see if a nonform widget needs to be signalled 
     for(var node=this.domNode; node.parentNode/*#5935*/; node=node.parentNode){ 
      var widget=dijit.byNode(node); 
      if(widget && typeof widget._onSubmit == "function"){ 
       widget._onSubmit(e); 
       break; 
      } 
     } 
    } 
}TypeError: Object doesn't support this property or method 

誰能幫助我? ......如何解決這個問題?... 在此先感謝

問候, Kamesh

回答

0

錯誤的youre表現是不相關的下面的代碼。正如dojotoolkit-src註釋所示,您的操作與用戶激活按鈕部分時的功能'處理程序有關。

應該可以解決這個

// << Value is all lower case 
dijit.byId("editRole").attr("Value",getRoleByName(role)); 

而且乾淨了一點編碼開關以「WTF」 - IM想這可能是語法高亮您選擇在這裏嘗試 - 或者是那些波浪線真的在你的代碼?

// What are these back-tilds doing here? 
switch(role)`` 
{ 
     case 'Basic User'   : return 1 
     case 'Network Operator'  : return 3 
     case 'System Administrator' : return 5 
     case 'Custom Level 1'  : return 11 
     case 'Custom Level 2'  : return 12 
     default: 
      return 1 
    // return works as your break does, it stops the switch 
} 

說你在修剪過程中遇到問題嗎?試試這個,修剪是不是在所有的JavaScript引擎

if(typeof String.prototype.trim !== 'function') { 
     String.prototype.trim = function() { 
       return this.replace(/^\s+|\s+$/g, ''); 
     } 
} 
+0

我看不到任何tidles實現... – starbeamrainbowlabs 2012-07-21 15:04:05

+0

感謝迅速的反應mschr ......你是right..actually問題是即時通訊使用role.toString( )。修剪()。這是造成問題......但如果我刪除toString轉換,總是返回默認值。 – kamesh 2012-07-21 15:36:37

+0

修剪不是一個完全原生的實現功能,虐待添加一個字符串原型擴展到我的答案然後 – mschr 2012-07-21 15:46:51

相關問題