<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var value = $("p").removeClass("intro");
});
});
</script>
<style>
.intro
{
font-size:120%;
color:red;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p class="intro">This is a paragraph.</p>
<p class="intro">This is another paragraph.</p>
<button>Remove the "intro" class from all p elements</button>
</body>
</html>
这是我删除某些类
我的问题的程序是,我怎么能知道,如果removeclass操作是成功还是失败?
$("p").removeClass("intro");
可以为此设置任何返回类型?
你可以使用'$(“p.intro”)。length' – Satpal 2014-09-03 09:56:20
你可以使用'.hasClass'函数。例如'$(“p”)。hasClass(“intro”);' – 2014-09-03 09:57:25
你可以使用hasClass() – jtromans 2014-09-03 09:57:35