使用jQuery延迟加载js文件

//异步加载js文件并调用函数
function delayCall(calledFunction, funcParams, jsUrl)
{
	if (eval('typeof '+calledFunction) == 'function') {
		eval(calledFunction+'(funcParams)');
	} else {
		jQuery.ajax({
			type: 'GET',
			url: jsUrl,
			data: {},
			dataType: 'script',
			cache: true,
			async: true,
			success: function () {
				eval(calledFunction+'(funcParams)');
			}
		});
	}
}

//同步加载js文件
function syncLoad(checkFunction, jsUrl)
{
	if (eval('typeof '+checkFunction) != 'function') {
		jQuery.ajax({
			type: 'GET',
			url: jsUrl,
			data: {},
			dataType: 'script',
			cache: true,
			async: false,
		});
	}
}


你可能感兴趣的:(js,jquery)