我的ASP.NET MVC项目中有一个依赖于Jquery的文件
// namespace pattern
var diem = diem || {};
diem .defineNamespace = function(ns_string) {
var parts = ns_string.split('.');
var parent = diem ;
var i;
if(parts[0] === "diem ") {
parts = parts.slice(1);
}
for(i = 0; i < parts.length; i += 1) {
if(typeof parent[parts[i]] === "undefined") {
parent[parts[i]] = {};
parent = parent[parts[i]];
}
return parent;
}
};
diem.defineNamespace('diem.utils');
// module pattern
diem.utils = (function() {
// private API
// ...
// public API
return {
handleFileInputs: function(container) {
$(container + ' ' + 'input[type="image"]').click(function(e) {
// prevent from submission
e.preventDefault();
// handle add/remove items
if($(this).hasClass('add')) {
$(this).parent().append('<p><input type="file" accept="image/jpeg,image/png,image/gif" name="files" /></p>');
} else {
$(this).parent().find('p:last-child').remove();
} // if($(this).hasClass('add')) {
});
}, // handleFileAttachments: function() {
handleLabelWidths: function(container) {
var max = 0;
$(container + ' ' + 'label.autoWidth').each(function() {
if($(this).width() > max) {
max = $(this).width();
}
});
$(container + ' ' + 'label.autoWidth').width(max + 5);
} // handleLabelWidths: function(container) {
} // return {
})(); // streamlined.utils = (function() {还有一个依赖于Modernizr库的代码。
如何将我的代码、JQuery、Modernizr和requirejs一起使用?
谢谢!
发布于 2012-08-23 21:36:48
假设您将所有脚本文件放在“.js”子目录中
<script data-main="scripts/main.js" src="scripts/require-jquery.js"></script>在main.js中
require(["jquery", "jquery.alpha", "jquery.beta"], function($) {
//the jquery.alpha.js and jquery.beta.js plugins have been loaded.
$(function() {
$('body').alpha().beta();
});
});https://stackoverflow.com/questions/12092643
复制相似问题