Javascript中的开关案例在IE8中不起作用
Switch case in Javascript is not working in IE8
代码片段:
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中得到了以下错误,但在Firefox中运行良好。。
开发者工具中的错误:
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
有人能帮我吗。。。如何克服这个问题?。。。
您显示的错误与以下代码无关。正如dojotolkit 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
}
在修剪时说你的击球问题?试试看,trim并不是在所有javascript引擎中都实现的
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^'s+|'s+$/g, '');
}
}
相关文章:
- Recaptcha在IE7和IE8中不起作用
- 在IE8中不起作用的元素上触发单击事件
- 数据-在IE8中不起作用
- getComputedStyle替换:currentStyle(IE8/7)不起作用
- IE8 jquery ajax头请求不起作用
- 显示隐藏的html表在javascript(IE8)中不起作用
- ScriptX 打印功能在 IE8 中不起作用
- Angularjs 跨源资源共享 (CORS) 发布或放置方法在 IE8 和 IE9 中不起作用
- ExtJs 5.0:forEach on Array of Objects在IE8中不起作用
- 将JSON对象转换为敲除observable在IE8中不起作用,但在所有其他浏览器中都起作用
- 聚焦函数在ie8中不起作用
- 启动网格在IE8中不起作用
- Svg标签在IE8中不起作用
- Twitter引导程序示例在IE8中不起作用
- 引导程序3在IE8中不起作用(已检查其他答案)
- IE8的Javascript占位符不起作用
- Javascript中的开关案例在IE8中不起作用
- 如果我添加 pageX 页面 Y 在 IE8 中不起作用<!文档类型 html>.
- getElementsByTagName和getElementsByClassName在IE8中不起作用
- 导航在IE8上不起作用