• 样式的使用


    样式的使用

    [doc]

    代码

    1. <!DOCTYPE html> 
    2. <html> 
    3. <head lang="en"> 
    4. <meta charset="UTF-8"> 
    5. <title>添加样式</title> 
    6. <!--样式表--> 
    7. <style> 
    8. .Item1{ 
    9. font-size: 2em; 
    10. color: #00FF00; 
    11. background-color: black; 
    12. } 
    13.  
    14. .Item2{ 
    15. font-size: 3em; 
    16. color: #37C2FB; 
    17. background-color: saddlebrown; 
    18. } 
    19. </style> 
    20. <script src="jquery-1.11.1.min.js"></script> 
    21. <script> 
    22. $(document).ready(function(){ 
    23. //设置样式 
    24. /*$("li").eq(2).css("background","red"); 
    25. $("li").eq(3).css({ 
    26. "background":"skyblue", 
    27. });*/ 
    28. //添加样式 
    29. $("li").addClass("Item1"); 
    30. $("li").eq(4).addClass("Item2"); 
    31. //删除样式 
    32. $("li").eq(7).removeClass("Item1"); 
    33. //切换样式 
    34. $("input").click(function(){ 
    35. $("li").eq(6).toggleClass("Item2"); 
    36. }); 
    37. //判断有没有某种样式 
    38. $("#btnName").click(function(){ 
    39. var hasDivItmClass = $("li").eq(7).hasClass("Item1"); 
    40. if(hasDivItmClass){ 
    41. $("li").eq(7).addClass("Item1"); 
    42. }else{ 
    43. $("li").eq(7).addClass("Item1"); 
    44. } 
    45. }); 
    46.  
    47. }); 
    48. </script> 
    49. </head> 
    50. <body> 
    51. <input type="button" value="切换样式" id="demo"/> 
    52. <input type="button" value="判断样式" id="btnName"/> 
    53. <ul > 
    54. <li>样式表的颜色1</li> 
    55. <li>样式表的颜色2</li> 
    56. <li>样式表的颜色3</li> 
    57. <li>样式表的颜色4</li> 
    58. <li>样式表的颜色5</li> 
    59. <li>样式表的颜色6</li> 
    60. <li>样式表的颜色7</li> 
    61. <li>样式表的颜色8</li> 
    62. </ul> 
    63. </body> 
    64. </html> 

    效果

    enter description here

    样式222.png

    每天叫醒的不是闹钟,而是梦想
  • 相关阅读:
    C# 16进制与字符串、字节数组之间的转换
    多文件上传方法
    超链接如何下载文件txt,word,excel等等
    asp.net不同类型文件读取处理
    .net二进制图片存储与读取的常见方法
    c#事务
    C#中的null和数据库中的null的区别
    Asp.net中Response.Charset 与Response.ContentEncoding区别
    导出到word
    js导出word
  • 原文地址:https://www.cnblogs.com/shuiyaodongwu310988929/p/5994521.html
Copyright © 2020-2023  润新知