我尝试使用JavaScript填充下拉列表,但在IE8中遇到以下错误:
消息:'1‘为null或不是对象行: 59字符:3代码:0
当我通过调试器(在本例中为JSBin)推送代码时,我在代码中看到以下错误:
第59行: var视图= $(‘#ai1ec- $selected_view -’+ matches1 );- 'matches‘超出范围使用。
JSBin中的这个错误会与IE8中的错误相关吗?当代码在Chrome、FF或IE9上运行时,任何错误都不会填充。
下面是有问题的代码片段。
// Make current view actively selected in view dropdown button.
var classes = $('body').attr( 'class' ).split( ' ' );
for ( i in classes ) {
// Extract current view from the body class.
var matches = /ai1ec-action-([\w]+)/.exec( classes[i] );
if ( matches != null ) break;
}
// Get the dropdown menu link of the active view.
var $selected_view = $( '#ai1ec-view-' + matches[1] );
// Replace contents of dropdown button with menu link, plus the caret.
$( '#ai1ec-current-view' )
.contents()
.remove()
.end()
.prepend( $selected_view.contents().clone() )
.append( '<span class="caret"></span>' );
// Deactivate all dropdown menu items.
$( '#ai1ec-view-dropdown .dropdown-menu li' ).removeClass( 'active' );
// Activate only currently selected dropdown menu item.
$selected_view.parent().addClass( 'active' );发布于 2012-09-14 21:43:05
不是的。超出范围的linter提示/错误/消息可能是因为变量是在for- in -loop的主体块中声明的;这应该可以工作。
然而,matches似乎是导致异常的null。只要matches不为null,您就会中断循环,但这并不能保证某些东西确实匹配-循环可能刚刚结束,而matches仍然为null。
顺便说一句:你不应该使用for-in-循环来枚举split返回的数组的属性,你想用一个普通的for-循环来迭代这些项。
https://stackoverflow.com/questions/12425633
复制相似问题