@@ -425,20 +425,34 @@ ko.bindingHandlers['checked'] = {
425
425
}
426
426
} ;
427
427
428
+ var attrHtmlToJavascriptMap = { 'class' : 'className' , 'for' : 'htmlFor' } ;
428
429
ko . bindingHandlers [ 'attr' ] = {
429
430
'update' : function ( element , valueAccessor , allBindingsAccessor ) {
430
431
var value = ko . utils . unwrapObservable ( valueAccessor ( ) ) || { } ;
431
432
for ( var attrName in value ) {
432
433
if ( typeof attrName == "string" ) {
433
434
var attrValue = ko . utils . unwrapObservable ( value [ attrName ] ) ;
434
-
435
+
435
436
// To cover cases like "attr: { checked:someProp }", we want to remove the attribute entirely
436
437
// when someProp is a "no value"-like value (strictly null, false, or undefined)
437
438
// (because the absence of the "checked" attr is how to mark an element as not checked, etc.)
438
- if ( ( attrValue === false ) || ( attrValue === null ) || ( attrValue === undefined ) )
439
+ var toRemove = ( attrValue === false ) || ( attrValue === null ) || ( attrValue === undefined ) ;
440
+ if ( toRemove )
439
441
element . removeAttribute ( attrName ) ;
440
- else
442
+
443
+ // In IE <= 7 and IE8 Quirks Mode, you have to use the Javascript property name instead of the
444
+ // HTML attribute name for certain attributes. IE8 Standards Mode supports the correct behavior,
445
+ // but instead of figuring out the mode, we'll just set the attribute through the Javascript
446
+ // property for IE <= 8.
447
+ if ( ko . utils . ieVersion <= 8 && attrName in attrHtmlToJavascriptMap ) {
448
+ attrName = attrHtmlToJavascriptMap [ attrName ] ;
449
+ if ( toRemove )
450
+ element . removeAttribute ( attrName ) ;
451
+ else
452
+ element [ attrName ] = attrValue ;
453
+ } else if ( ! toRemove ) {
441
454
element . setAttribute ( attrName , attrValue . toString ( ) ) ;
455
+ }
442
456
}
443
457
}
444
458
}
0 commit comments