运行代码 缩小
喵记
HTML代码
复制 格式化 注释 注释 清空
放大
x
 
1
<!DOCTYPE html>
2
<html>
3
    <head>
4
        <meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
5
        <script type="text/javascript" src="//apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js">
6
        </script>
7
    </head>
8
    <body>
9
        <span id = "s1">我是测试一号
10
        </span>
11
        <input type = "button" id = "btn1" value = "一号变红" />
12
        <input type = "button" id = "btn2" value ="一号变绿也变大"/>
13
        <input type = "button" id = "btn3" value = "直接添加class变一号"/>
14
        <input type = "button" id = "btn4" value = "替换class变一号" />
15
        </br>
16
    <span id="s2">我是测试二号</span> 
17
    <form>
18
    <input type="text" id ="txt1" value="aa" />
19
    <input type="text" id ="txt2" value="bbb" />
20
    <input type ="button" id ="btntt" value = "显示文本框的内容" />
21
    </br>
22
    <p id = "t3">aaa</p>
23
    <input type ="button" id ="btn666" value = "设置文本内容为仙女最美" />
24
    <input type ="button" id ="btn777" value = "设置文本内容加一个span,喵记最美" />
25
    </form>
26
    </body>
27
</html>
28
CSS代码
复制 格式化 注释 注释 颜色 清空
放大
xxxxxxxxxx
24
 
1
body {
2
    background-image: url(/themes/zhan/styles/images/bg-body.jpg);
3
}
4
.main {
5
    width: 80%;
6
    margin: auto;
7
    text-align: center;
8
    border: 1px solid #e0e0e0;
9
    box-shadow: 0 0 2px #ddd;
10
    word-wrap: break-word;
11
    padding: 10px;
12
    border-radius: 3px
13
}
14
.test{
15
    color:blue;
16
    font-size:24px;
17
}
18
.test2 {
19
  color:purple;
20
  font-size:18px;
21
}
22
23
24
JS代码
复制 格式化 注释 注释 清空
放大
xxxxxxxxxx
28
 
1
$(document).ready(function(){
2
    $("#btn1").click(function(){
3
        $("#s1").css("color","red");
4
    });
5
  $("#btn2").click(function(){
6
    $("#s1").css({"color":"green","font-size":"32px"});
7
  });
8
  $("#btn3").click(function(){
9
    $("#s1").addClass("test");
10
  });
11
 $("#btn4").click(function(){
12
    $("#s1").toggleClass("test2");
13
 });
14
  $("#btntt").click(function(){
15
    alert($("#txt1").val());
16
    alert($("#txt2").val());
17
    alert($("input[type=text]").val());
18
  });
19
  
20
  $("#btn666").click(function(){
21
    $("#t3").text("仙女最美");
22
  });
23
  $("#btn777").click(function(){
24
    $("#t3").html("<span>喵记最美</span>");
25
  });
26
});
27
28
名称
9.5 获取和设置
分类
jQuery实例
描述
收藏