<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>移除元素样式</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
div
{
padding: 8px;
width: 180px;
}
.blue
{
background-color: Blue;
}
.white
{
color: White;
}
</style>
</head>
<body>
<h3>removeClass()方法移除元素样式</h3>
<div id="content" class="blue white">我脱下了一件蓝色外衣</div>
<a id="link" href="www.baidu.com">hi</a>
<script type="text/javascript">
// Get href content
var $hrefContent = $("#link").attr("href");
// Display it
$("#content").html($hrefContent);
// Remove href attribute
$("#link").removeAttr("href");
// Reassign value
$hrefContent = $("#link").attr("href");
// Judge undifined
if(typeof($hrefContent) == "undefined")
$hrefContent = "undefined";
// Display href content again
$("#content").html($hrefContent);
// Remove class
$("#content").removeClass("white blue");
$("#content").html($("#link").attr("href"));
</script>
</body>
</html>
JQuery removeAttr() and removeClass()
最新推荐文章于 2023-03-10 16:13:26 发布