JavaScript を使用してドロップダウン リストに入力しようとしていますが、IE8 で次のエラーが発生します。
メッセージ: '1' は null またはオブジェクトではありません 行: 59 文字: 3 コード: 0
デバッガー (この場合は JSBin) を介してコードをプッシュすると、コードに次のエラーが表示されます。
59 行目: var $selected_view = $( '#ai1ec-view-' + matches[1] ); --- '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' );