简体   繁体   English

在页面中包含JavaScript和CSS(jQuery)

[英]Including JavaScript and CSS in a page (jQuery)

I recently came across the includeMany jQuery plugin to include external JavaScript and CSS files into a page. 我最近遇到了includeMany jQuery插件,将外部JavaScript和CSS文件包含到页面中。 Although it was released in early 2009 there are NO references in blogs or elsewhere. 虽然它在2009年初发布,但在博客或其他地方没有引用。 I wonder if it's usable? 我想知道它是否可用? What is the experience using it? 使用它的经验是什么?

You can include JavaScript and CSS using the example below. 您可以使用以下示例包含JavaScript和CSS。 There is no need for any plugins. 不需要任何插件。

To include JavaScript code, do this: 要包含JavaScript代码,请执行以下操作:

$.getScript("youpathtoscript.js",function() {
            //this script is loaded
});

To include CSS files: 要包含CSS文件:

$("<link/>", {
   rel: "stylesheet",
   type: "text/css",
   href: "styles/yourcss.css"
}).appendTo("head");

For collection of CSS/JavaScript import (including): 用于CSS / JavaScript导入的收集(包括):

Eval alternative: Eval替代方案:

$("<script></script>", {type: "text/javascript",})
.text("alert('your function');")
.appendTo("head");

Embedded CSS: 嵌入式CSS:

$("<style></style>", {type: "text/css",})
.text("#you{css:rule}")
.appendTo("head");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 JavaScript(包括 CSS 和 img)计算页面上的所有图像 - How can count all images on a page with JavaScript (including CSS and img) 包括CSS和javascript小部件,而不会弄乱主机页面 - Including CSS with a javascript widget without messing up host page 网页上是否存在包括未使用的Java脚本或JQuery调用在内的性能/安全性惩罚? - Is there a Performance/Security Penalty Including Unused Javascript or JQuery Calls on a Web Page 将javascript包含到html页面 - Including javascript to an html page Javascript不包括jQuery插件? - Javascript not including jQuery plugin? 用于检查CSS类是否在没有Jquery的页面上的Javascript - Javascript to check if a CSS class is on the page without Jquery 如何使用 CSS 重定向到 Javascript 或 Jquery 中的页面 - how to redirect to a page in Javascript or Jquery with CSS jQuery:getScript,用于将Javascript包含到Javascript中 - jQuery: getScript for including Javascript into Javascript 使用Jquery / Javascript / CSS在页面加载中进行CSS“转换:旋转” - CSS 'Transform: rotate' on Page Load using Jquery/Javascript/CSS javascript或jquery代码以获取iframe中网页的整个文本内容(包括/排除该页面上的链接) - javascript or jquery code to obtain entire text content of web page within an iframe (including/excluding links on that page)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM