- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个小书签,它需要访问 jquery-ui 和 jquery min。当然,关注的是页面可能已经加载了 jQuery,应该避免冲突。
使用位于 http://benalman.com/code/javascript/jquery/jquery.ba-run-code-bookmarklet.js 的 Ben Alman 的代码我已经能够优雅地引入 jQuery 并在 UI 中进行加载以进行加载但似乎存在延迟问题并且 jQuery UI 尚未准备好立即运行...
有没有更好的方法来处理在执行实际代码之前按顺序加载两个脚本?
(function( window, document, jQuery, req_version, callback, callback_orig, parent, script ){
if ( !window[jQuery] || req_version > window[jQuery].fn.jquery ) {
parent = document.documentElement.childNodes[0];
script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js';
parent.appendChild(script);
callback_orig = callback;
callback = function($, L) {
'$:nomunge, L:nomunge';
$(script).remove();
callback_orig( $, L );
};
}
if (typeof jQuery.ui == 'undefined'){
parent = document.documentElement.childNodes[0];
scriptui = document.createElement('script');
scriptui.type = 'text/javascript';
scriptui.src = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js';
parent.appendChild(scriptui);
alert('Loading your matches...');
}
(function loopy($){
'$:nomunge'; // Used by YUI compressor.
( $ = window[jQuery] ) && req_version <= $.fn.jquery
? callback( parent ? $.noConflict(1) : $, !!parent ) : setTimeout( loopy, 50 );
})();
})( window, document, 'jQuery', '1.3.2',
function($,L) {
'$:nomunge, L:nomunge';
<all the jquery stuff goes here>
Using jQuery UI in a Bookmarklet 也有类似的问题有深入的答案,但我无法将其从 CoffeeMarklet 转换为“标准”js。
最佳答案
在这里查看我的要点 - 这是一个用于加载 jQuery 的书签模板,但您可以指定要在执行前加载的其他脚本和 css。
https://gist.github.com/2897748
你像这样初始化它。
编辑:如果你需要加载依赖,你可以创建一个数组并根据不同的条件将东西插入其中。
var jsDependencies = [];
// This will only load jQuery UI if it does not exist already.
// Of course if you rely on the page's copy, you have to do some
// more advanced things to check for versions and whatnot.
if(!window.jQuery || !window.jQuery.ui){
jsDependencies.push('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js');
}
var MyBookmarklet = MyBookmarklet || new Bookmarklet({
// debug: true, // use debug to bust the cache on your resources
css: ['/my/style.css'],
js: jsDependencies,
// jqpath: '/my/jquery.js', // defaults to google cdn-hosted jquery
ready: function(base) { // use base to expose a public method
base.init = function(){
// doStuff();
}
base.init();
}
});
关于javascript - 如果尚未加载 jQuery 和 jQuery UI,则在 Bookmarklet 中加载它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11315595/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!