码迷,mamicode.com
首页 > Web开发 > 详细

[ jquery 方法 removeClass([class|fn]) ] 此方法为每个匹配的元素删除指定的类名

时间:2016-06-22 01:44:15      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:

从所有匹配的元素中删除全部或者指定的类:

  如果参数是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‘).removeClass(function(index,oldClass){
           console.log(oldClass);
           var reg = /\baddTwo\b/;
           return oldClass.replace(reg,‘‘);
        });
    });
</script>
</head>
<body>
   <input type=‘text‘ id=‘user‘ required="required" value=‘user‘ class=‘addOne addTwo‘/>
</body>
</html>

 

[ jquery 方法 removeClass([class|fn]) ] 此方法为每个匹配的元素删除指定的类名

标签:

原文地址:http://www.cnblogs.com/mysearchblog/p/5605546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!