日期:2014-05-16  浏览次数:20317 次

自己写的测试前端页面js

testConfig = {
    base_source_uri : 'http://static.test.com',
    script_sourc_uri : '/script/',
    style_source_uri : '/style/',
    
    setBaseSourceUri : function(source) {
        this.base_source_uri = source;
    },
    setScriptSourceUri : function(source) {
        this.script_sourc_uri = source;
    },
    setStyleSourceUri : function(source) {
        this.style_source_uri = source;
    }
?

?
写道
models = {};
models.login = {script:'login.js',css:'login.css'};
models.test = {script:'test.js',css:'test.css'};
?
(function() {

    function loadScript(source) {
        script = document.createElement('script');
        script.type = 'text/javascript';
        script.language = 'javascript';
        script.charset = "UTF-8";
        script.src = source;

        script.onload = script.onreadystatechange = function() {
            done = false;
            if(!done && (!script.readyState || script.readyState == 'loaded' || script.readyState == 'complete')) {
                done = true;
                script.onload = script.onreadystatechange = null;
            }
        }
        document.getElementsByTagName("head")[0].appendChild(script);
    }

    function loadCss(source) {
        var link = document.createElement('link');
        link.rel = 'stylesheet';
        link.type = 'text/css';
        link.media = 'screen';
        link.href = source;
        document.getElementsByTagName('head')[0].appendChild(link);
    }

    function loadModel(name) {
        model = models[name];
        style_source = testConfig.base_source_uri + testConfig.style_source_uri + models[name].css;
        script_source = testConfig.base_source_uri + testConfig.script_sourc_uri + models[name].script;

        loadCss(style_source);
        loadScript(script_source);
    }

    testLoaser = {
        localCommon : function() {

        },
        loadTestCommon : function() {

        },
        loadTestModel : function(testModelName) {
            loadModel(testModelName);
        }
    };

    window.loadTestModel = testLoaser.loadTestModel;

})()

?测试页面代码

 <script type="text/javascript" charset="UTF-8">
            (function() {
                loadTestModel('test');
            })();

        </script>
?