Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript函数。我真的很喜欢这种样式的行为像正常的CSS,在这种情况下,这意味着没有惊喜!我只是稍微修改了这个函数,以便它为每个选择器重新创建CSS,而不是附加到现有样式。这是为了在删除样式时,允许样式返回到主题默认设置,而不是上一个设置。J_Javascript_Jquery_Html_Css_Jquery Selectors - Fatal编程技术网

使用JavaScript函数。我真的很喜欢这种样式的行为像正常的CSS,在这种情况下,这意味着没有惊喜!我只是稍微修改了这个函数,以便它为每个选择器重新创建CSS,而不是附加到现有样式。这是为了在删除样式时,允许样式返回到主题默认设置,而不是上一个设置。J

使用JavaScript函数。我真的很喜欢这种样式的行为像正常的CSS,在这种情况下,这意味着没有惊喜!我只是稍微修改了这个函数,以便它为每个选择器重新创建CSS,而不是附加到现有样式。这是为了在删除样式时,允许样式返回到主题默认设置,而不是上一个设置。J,javascript,jquery,html,css,jquery-selectors,Javascript,Jquery,Html,Css,Jquery Selectors,使用JavaScript函数。我真的很喜欢这种样式的行为像正常的CSS,在这种情况下,这意味着没有惊喜!我只是稍微修改了这个函数,以便它为每个选择器重新创建CSS,而不是附加到现有样式。这是为了在删除样式时,允许样式返回到主题默认设置,而不是上一个设置。JavaScript闭包的好例子。 <p> This is normal text <br> <br> <em>This is italic text</em> &l

使用JavaScript函数。我真的很喜欢这种样式的行为像正常的CSS,在这种情况下,这意味着没有惊喜!我只是稍微修改了这个函数,以便它为每个选择器重新创建CSS,而不是附加到现有样式。这是为了在删除样式时,允许样式返回到主题默认设置,而不是上一个设置。JavaScript闭包的好例子。
<p>
  This is normal text
  <br>
  <br>
  <em>This is italic text</em>
  <br>
  <br>
  <strong>This is bold text</strong>
  <br>
  <br>
  <strong><em>This is bold italic text</em></strong>
  <br>
  <br>
  <em><strong>This is also bold italic text</strong></em>
  <br>
  <br>
</p>

<button>
  Style it!
</button>
p em strong,
p strong em {
      color: red;
    }

p strong {
  color: blue;
}
(function($) {
  $('button').on('click', function() {
    $('p strong').css('color', 'turquoise');
  });
})(jQuery);
$('p > strong').css('color', 'turquoise');
$('p strong').not('p em strong').css('color', 'turquoise');
var createCSSStyle = (function() {
    var styleSheet = null;
    return function(selector, cssOptions) {
        if (styleSheet == null) {
            styleSheet = document.createElement('style');
            styleSheet.type = 'text/css';
            document.getElementsByTagName('head')[0].appendChild(styleSheet);
        }

        var text = " " + selector + " {";
        for(var prop in cssOptions)
            text += prop + ":" + cssOptions[prop] + ";";
        text += "}";

        styleSheet.innerHTML += text;
    };
})();
createCSSStyle('p  strong', { 'color' : 'turquoise' });
(function($) {
   var styles = [];
   function styler(style){
      styles.push(style);
      $("#styler").html(styles.join("\n"));
   }
   $('button').on('click', function() {
      styler("p strong {color: turquoise;}")
   });

  $("head").append("<style id='styler'></style>")
})(jQuery);