jQuery.attr ('class') 和 jQuery.attr ('className') 的区别

史阳晖
2023-12-01
原文地址为: jQuery.attr ('class') 和 jQuery.attr ('className') 的区别

class="cnblogs_Highlighter">
<div id="div1" class='A B C D'></div>

将div1里面class全部修改成E F G H

$('#div1').attr('class','E F G H');
//二者是一样的
$('#div1').attr('className','E F G H');

 

但是

document.getElementById('div1').className='E F G H' //正常
document.getElementById('div1').class='E F G H' //失败

jQuery里面

jQuery.props = {
    "for": "htmlFor",
    "class": "className",
    readonly: "readOnly",
    maxlength: "maxLength",
    cellspacing: "cellSpacing",
    rowspan: "rowSpan",
    colspan: "colSpan",
    tabindex: "tabIndex",
    usemap: "useMap",
    frameborder: "frameBorder"
};

  

name = notxml && jQuery.props[ name ] || name;

转载请注明本文地址: jQuery.attr ('class') 和 jQuery.attr ('className') 的区别
 类似资料: