现在的位置: 首页 > 综合 > 正文

jQuery简单例子-3

2012年11月21日 ⁄ 综合 ⁄ 共 1390字 ⁄ 字号 评论关闭

<html>
 <head>

<style type="text/css">

.high{
font-weight:bold;
color: red
}

.another{
font-style:italic;
color:green

}

</style>

 <script type="text/javascript" src="jquery-1.7.2.js"></script>

<script type="text/javascript">

 $(function()
 {
    $("input:eq(0)").click(function()
    {
        alert($("p").attr("class"));
    });
    
    $("input:eq(1)").click(function()
    {
        $("p").attr("class","high");
    });

    $("input:eq(2)").click(function()
    {
        $("p").addClass("high");
    });

    $("input:eq(3)").click(function()
    {
        $("p").removeClass("high");
    });

    $("input:eq(4)").click(function()
    {
        $("p").removeClass(); //删除全部的class属性的值
    });

    $("input:eq(5)").click(function()
    {
        //class的值有another则删除another,若没有则添加another
        $("p").toggleClass('another');        
    });

    $("input:eq(6)").click(function()
    {
        //alert($("p").hasClass('another')); //判断class的值里是否有another
        alert($('p').is('.another'));
    });

 });

</script>

 </head>

 <body>
 
<input type="button" value="button1">
<input type="button" value="button2">
<input type="button" value="button3">
<input type="button" value="button4">
<input type="button" value="button5">
<input type="button" value="button6">
<input type="button" value="button7">

<p title="hello world" class="hello">您认为java好不好呢?</p>

 <ul>

 <li title="1">好</li>
 <li title="2">很好</li>
 <li title="3">非常好</li>
 <li title="4">特别好</li>
 <li title="5">太好了</li>
 <li title="6">好的无法描述了</li>

</ul>

 </body>
</html>

抱歉!评论已关闭.