[ jquery 方法 addClass(class|fn) ] 此方法为每个匹配的元素添加指定的类名

此函数必须返回一个或多个空格分隔的class名,如果第二个参数是callback,那么需要返回的是属性值,函数传参解释如下:

  1.index参数为对象在这个集合中的索引值

  2.class参数为这个对象原先的class属性值

实例:

<!DOCTYPE html>
<html lang='zh-cn'>
<head>
<title>Insert you title</title>
<meta http-equiv='description' content='this is my page'>
<meta http-equiv='keywords' content='keyword1,keyword2,keyword3'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- <script type='text/javascript' src='./js/jquery-3.0.0.js'></script> -->
<script type='text/javascript' src='./js/jquery-1.12.1.min.js'></script>
<style type='text/css'>
   input{font:400 13px/20px 'Courier New';color:#000;}
   .addOne{padding:0 8px;}
   .addTwo{color:#999;}
</style>
<script type='text/javascript'>
    $(function(){
        $('#user').addClass('addOne addTwo');
    });
</script>
</head>
<body>
   <input type='text' id='user' required="required" value='user'/>
</body>
</html>
原文地址:https://www.cnblogs.com/mysearchblog/p/5605525.html