show() 和 html() 的使用:
1
|
$("span").addClass("css_style").show().html("foo");
|
首先增加样式,然后用 show() 显示隐藏的匹配元素,html("foo") 设置每一个匹配元素的 html 内容。
Code
01
|
<style>
|
02
|
.nowamagic
|
03
|
{
|
04
|
color:red;
|
05
|
}
|
06
|
</style>
|
07
|
08
|
<script type="text/javascript">
|
09
|
$(document).ready(function(){
|
10
|
$("span").addClass("nowamagic").show().html("简明现代魔法");
|
11
|
//对比:$("a").addClass("test").html("cssrain");
|
12
|
});
|
13
|
</script>
|
14
|
15
|
<span>我才是原本的内容!我被 JQuery 改了</span>
|
上述 JQuery 实现了什么呢?首先,它找到 span 的 HTML 元素,然后给它加上名为 nowamagic 的 CSS 样式,再把这个 HTML 的元素的换成 html() 方法内的参数。
热门源码