首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jquery设立CSS文件中的样式

2012-08-15 
jquery设置CSS文件中的样式html[color#FF0000][/color]html xmlnshttp://www.w3.org/1999/xhtmlhea

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

热点排行