日期:2014-05-16  浏览次数:20406 次

jquery设置CSS文件中的样式
html[color=#FF0000][/color]
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <link href="MyStyle/MyStyles.css" rel="stylesheet" type="text/css" />
  <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
  <script src="MyJs/myjs.js" type="text/javascript"></script>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <button id="btnSet">设置样式</button>
  <p id="pId">sdfadfasdf</p>
  <p class="pCla">测试文字段落的动画</p>
  <button id="btnGet">获取样式</button>
  </div>
  </form>
</body>
</html>

myjs.js内容[color=#FF00FF][/color]
$(document).ready(function () {
  $("button#btnSet").click(function () {
  $("p#pId").addClass("firstClass");
  return false;
  });
  $("button#btnGet").click(function () {
  var st = $("p#pId").css("color");
  alert(st);
  return false;
  });
});

MyStyles.css文件内容[color=#FF0000][/color]
body {
}

firstClass
{
  font-size:14;
  color:Red;
  font-family:@华文行楷;
}

secondClass
{
  font-size:7;
  color:Black;
  font-family:@宋体;
}

疑问:addClass没有设置成功,用css("color")获取到的是白色而非红色,哪位指教下小弟

------解决方案--------------------
.firstClass

------解决方案--------------------
探讨
.firstClass

------解决方案--------------------
button#btnSet 为什么不直接#btnSet