jQuery包括CSS [英] jQuery include css

查看:50
本文介绍了jQuery包括CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在<body><head>内添加css样式,并将其放置在javascript文件中,如下所示:

How to add css styles inside <body> or <head>, placed in javascript file like this:

<style type="text/css">
    .popup-bg {
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: #eee;
    }
</style>

唯一的方法是在javascript中编写CSS,无法访问html或任何外部CSS.

The only way is to write css inside javascript, there is no access to html or any external css.

谢谢.

推荐答案

使用 addClass 的jquery方法:

Use addClass method of jquery:

$('body').addClass('popup-bg');

更新:

  $(function(){
    $('head').append('
      <style type="text/css">
        .popup-bg {
            position: fixed;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background: #eee;
        }
      </style>
    ');
  });

这篇关于jQuery包括CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆