English 中文(简体)
将js案卷附在一个js案上,但带有J Query错!
原标题:attaching js files to one js file but with JQuery error !

我想创建一只 j子,包括每个 j子的档案,以便把档案交给头部。

但是,我正在发现这一错误。

Microsoft JScript runtime error: Object expected

这是我的法典:

var baseUrl = document.location.protocol + "//" + document.location.host +  /yabant/ ;

// To find root path with virtual directory
function ResolveUrl(url) {
    if (url.indexOf("~/") == 0) {
        url = baseUrl + url.substring(2);
    }
    return url;
}

// JS dosyalarının tek noktadan yönetilmesi
function addJavascript(jsname, pos) {
    var th = document.getElementsByTagName(pos)[0];
    var s = document.createElement( script );
    s.setAttribute( type ,  text/javascript );
    s.setAttribute( src , jsname);
    th.appendChild(s);
}

addJavascript(ResolveUrl( ~/js/1_jquery-1.4.2.min.js ),  head );
$(document).ready(function() {
    addJavascript(ResolveUrl( ~/js/5_json_parse.js ),  head );
    addJavascript(ResolveUrl( ~/js/3_jquery.colorbox-min.js ),  head );
    addJavascript(ResolveUrl( ~/js/4_AjaxErrorHandling.js ),  head );
    addJavascript(ResolveUrl( ~/js/6_jsSiniflar.js ),  head );

    addJavascript(ResolveUrl( ~/js/yabanYeni.js ),  head );
    addJavascript(ResolveUrl( ~/js/7_ResimBul.js ),  head );
    addJavascript(ResolveUrl( ~/js/8_HaberEkle.js ),  head );
    addJavascript(ResolveUrl( ~/js/9_etiketIslemleri.js ),  head );
    addJavascript(ResolveUrl( ~/js/bugun.js ),  head );
    addJavascript(ResolveUrl( ~/js/yaban.js ),  head );
    addJavascript(ResolveUrl( ~/embed/bitgravity/functions.js ),  head );
});

Paths are right. I wanted to show you folder structure and watch panel: alt text

任何帮助都将受到高度赞赏。

最佳回答

我认为,问题是,在你使用全球美元时,酒吧是装满的。 根据,Loading gusts Without Blocking,这一机制并不总是在IE中保存执行令。

简单的解决办法是使用静态文字标签来装饰。 页: 1

<script type="text/javascript" "/js/1_jquery-1.4.2.min.js" />

但是,你真的需要等待准备的活动才能装上其他文字,或者你只需要装饰吗?

问题回答
// url=> http:  +  //  + localhost:4399  + /yabant/
//       ----     ----   --------------    --------
//     protocol + "//" +     host        +  /virtualDirectory/ 
var baseUrl = document.location.protocol + "//" + document.location.host +  /yabant/ ;

// If there is "~/" at the begining of url, replace it with baseUrl
function ResolveUrl(url) {
    if (url.indexOf("~/") == 0) {
        url = baseUrl + url.substring(2);
    }
    return url;
}

// Attaching scripts to any tag
function addJavascript(jsname, pos) {
    var th = document.getElementsByTagName(pos)[0];
    var s = document.createElement( script );
    s.setAttribute( type ,  text/javascript );
    s.setAttribute( src , jsname);
    th.appendChild(s);
}

// I want to make sure jQuery is loaded?
addJavascript(ResolveUrl( ~/js/1_jquery-1.4.2.min.js ),  head );

var loaded = false; // assume it didn t first and if it is change it to true
function fControl() {
    // alert("JQUERY is loaded?");
    if (typeof jQuery ==  undefined ) {
        loaded = false;
        fTry2LoadJquery();
    } else {
        loaded = true;
        fGetOtherScripts();
    }
}

// Check is jQuery loaded 
fControl();

function fTry2LoadJquery() {
    // alert("JQUERY didn t load! Trying to reload...");
    if (loaded == false) {
        setTimeout("fControl()", 1000);
    } else {
        return;
    }
}

function getJavascript(jsname, pos) {
    // I want to retrieve every script one by one
    $.ajaxSetup({ async: false,
        beforeSend: function() {
            $.ajaxSetup({ async: false });
        },
        complete: function() {
            $.ajaxSetup({ async: false });
        },
        success: function() {
            //
        }
    });

    $.getScript(ResolveUrl(jsname), function() { /* ok! */ });
}

function fGetOtherScripts() {
    // alert("Other js files will be load in this function");

    getJavascript(ResolveUrl( ~/js/5_json_parse.js ),  head );
    getJavascript(ResolveUrl( ~/js/3_jquery.colorbox-min.js ),  head );
    getJavascript(ResolveUrl( ~/js/4_AjaxErrorHandling.js ),  head );
    getJavascript(ResolveUrl( ~/js/6_jsSiniflar.js ),  head );

    getJavascript(ResolveUrl( ~/js/yabanYeni.js ),  head );
    getJavascript(ResolveUrl( ~/js/7_ResimBul.js ),  head );
    getJavascript(ResolveUrl( ~/js/8_HaberEkle.js ),  head );
    getJavascript(ResolveUrl( ~/js/9_etiketIslemleri.js ),  head );
    getJavascript(ResolveUrl( ~/js/bugun.js ),  head );
    getJavascript(ResolveUrl( ~/js/yaban.js ),  head );
    getJavascript(ResolveUrl( ~/embed/bitgravity/functions.js ),  head );
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签