我的HTML代码没有实现CSS样式.. CSS文件中的边框没有实现。 我试过FirefoxIE。请提供您的输入。CSS类不按预期工作
请找到下面的代码:
HTML
<html>
<head>
<link href="file://c:/jquery/chapter-1/begin/styles/my_style.css" rel="stylesheet">
</head>
<body>
<div id="header" class="no_hover"><h1>Header</h1></div>
<button type="button" id="btn1">Click to Add</button>
<button type="button" id="btn2">Click to Remove</button>
<script src="file://c:/jquery/chapter-1/begin/scripts/jquery.js" type="text/javascript"></script>
<script src="file://c:/jquery/chapter-1/begin/scripts/test4.js" type="text/javascript"></script>
</body>
</html>
JS文件
$(document).ready(function() {
$("#btn1").click(function(){
$("#header").addClass("hover");
$("#header").removeClass("no_hover");
});
$("#btn2").click(function(){
$("#header").removeClass("hover");
$("#header").addClass("no_hover");
});
});
CSS文件
.hover{
border: solid #f00 3px;
}
.no_hover{
border: solid #000 3px;
}
是否浏览器的错误控制台打印一个错误,它无法收集样式表?我猜是这样。也许它有助于在'file://'后面添加第三个斜杠。 – YMMD 2012-04-27 17:03:51
你真的需要两种风格吗?如果他们正在重新定义相同的事物(边界),则只需要颠倒CSS .hover和.no_hover的顺序,然后切换.hover,因为它将替换.no_hover(由于默认的.no_hover而导致反向) – 2012-04-27 17:26:10
猜想边框的简写是: border:1px#000 solid; – KBN 2012-04-27 17:26:18