zoukankan      html  css  js  c++  java
  • 如果删除行内样式中某一个 属性

    如果删除行内样式中某一个 属性,

    例下面: H2 本身有 font-size:12px; margin:0; padding:0;

    点击事件  加了一个 border","1px dashed red",

    则次点击 把 border 去了,  保留font-size:12px; margin:0; padding:0;

    如何实现

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    </head>
    
    <body>
    <div class="oDiv">
      <h2 style="font-size:12px; margin:0; padding:0;">无标题文档无标题文档无标题文档无标题文档</h2>
    </div>
    </body>
    </html>
    <script type="text/javascript" src="jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
    
    
    $(function(){
        
         $("h2").click(function(){
               
               $(this).css("border","1px dashed red");
               
                var objs=$(this).attr("style");
                
             })
        
        })
    </script>

      估计也有其它办法   现在在朋友的帮忙下, 用一个全局变量 做了一个判断, 也能实现 切换的效果
    代码如下:

    <script type="text/javascript">
    $(function(){
        var NoY=1;
         $("h2").click(function(){
                if(NoY==1){
                     $(this).css("border","1px dashed red");
                     NoY=0;
               
                    }else{
                         $(this).css("border","none");
                         NoY=1;
                        }
                
             })
        
        })
    </script>
  • 相关阅读:
    Codeforces Round #261 (Div. 2) D
    数据类型总结之列表字典
    while +for+字符串
    20150304+JQuery+AJax+插件-02
    20150304+JQuery+AJax+插件-01
    20150303+JQuery选择器-02
    20150303+JQuery选择器-01
    20150302+JQuery-02
    20150302+JQuery-01
    20150228--Ajax2-02
  • 原文地址:https://www.cnblogs.com/yjhua/p/4806543.html
Copyright © 2011-2022 走看看