首先在文件中引用:

<script type="text/javascript" src="../Library/jquery1.3.1/dist/jquery.js"></script>

<script type="text/javascript" src="hello.js"></script>

页面中有一个元素的类名为hello:

<div class=’hello’></div>

hello.js文件只有简单的内容:

$(document).ready(function() {
  $('.hello').addClass('hellocss');
});

其中hellocss为CSS样式表:

.hellocss{
  font-style: italic;
  border: 1px solid #888;
  padding: 0.5em;
  margin: 0.5em 0;
  background-color: #ffc;
}

这样打开页面后class为hello的div的样式就会设置成hellocss的样式.

posted on 2009-06-08 12:23  garfieldtom  阅读(180)  评论(0编辑  收藏  举报