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语句的javascript方法时,我在IE8中遇到错误,但在FF工作正常..
开发人员工具中的错误:
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 :(得分:0)
您显示的错误与以下代码无关。正如dojotoolkit-src评论所表达的那样,当用户激活按钮部分时,它与函数'Handler有关。'
应该解决这个问题
// << Value is all lower case
dijit.byId("editRole").attr("Value",getRoleByName(role));
还有一个带有'WTF'的清洁编码开关 - 我认为这可能是你在这里试验的语法突出 - 或者你的代码中是否有这些代号?
// 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, '');
}
}