Archive for 二月, 2010

js调试函数

Posted in 默认分类 on 二月 23rd, 2010 by admin – 1 Comment

参考php的debug函数修改了一下JS版的。 firebug 下使用控制台 ie使用 alert弹出

/**
 * 内部调试
 **/
function debug(v){
    if(window.console && window.console.log){
        window.console.log(v);
    }else{
        alert(v);
    }
}

通过script标签增加JS

Posted in 前端技术 on 二月 21st, 2010 by admin – Be the first to comment

工作需要在前端的代码通过xxx.js?m=m&x=x 的方法来通过js加载JS文件。



    
        
        
    
    
     

JS:

//MS闭包,不让代码互相影响,我也用的不多
(function(){

	var simcn = {
		src:[],
		init:function(){
			var __g = document.getElementById('simcnworkframe');
			this.srcUrl(__g.src);
		},
		run:function(){
			this.init();
			var head = document.getElementsByTagName('head')[0];
			var j=0;
			for(i in this.src){
				var t = document.createElement('script');
				t.src = this.src[i] + '.js' ;
				t.id  = "simc_" + this.src[i];
				head.appendChild(t);
			}
		},
		srcUrl:function(_u){
			var jl = _u.split('.js?')[1].split('&');
			for(i in jl){
				this.src.push(jl[i].split('=')[1]);
			}
		}
	};	

	simcn.run();

})()

//m.js
alert('m.js')

//c.js
alert('c.js')

//v.js
alert('v.js')