我创建了一个 CSS 切换器,但我只需要更改带有class="red"
for 的元素body
。我该怎么做?
<html>
<head>
<jdoc:include type="head" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="/js/modernizr-2.0.6.custom.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="/js/jquery.cookies.2.2.0.min"></script>
</head>
<body class="front">
<select class="style-change">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
<script>
$(function(){
$('.style-change').change(function(){
$('link[rel="stylesheet"]')
.attr("href", $(this).val() + ".css");
});
});
</script>
</body>
</html>
演示Here