`
ileson
  • 浏览: 210554 次
  • 性别: Icon_minigender_1
  • 来自: 河南省
社区版块
存档分类
最新评论

javascript 积累

    博客分类:
  • RIA
阅读更多
/**
 * 判断是不是enter键
 * 
 * @return
 */
function isEnter() {
	if (window.event.keyCode == 13) {//event.keyCode
		return true;
	} else {
		return false;
	}
}

/**
 *得到当前号加一字符串
 */
function getCurNumAddOne(curnum){
	alert("hello invoice"+curnum);
	var result;
	var str=new String(curnum);//javascript 中的String
	var intStr=str*1;
	intStr++;
	var result=new String(intStr);
	while(result.length<str.length){
		result="0"+result;
	}
	intStr='';
	return result;
}

	/**
	 *四舍五入
	 */
	function number(){
		var a=3.13159265358279643383279
		alert(a.toFixed(4));
	}



/**
	 *清空表单.
	 *by net
	 *
	 */
	function clearForm(form) {
		// iterate over all of the inputs for the form
		$(':input', form).each(function() {
			var type = this.type;//获取某个input 里的type
			var tag = this.tagName.toLowerCase(); // normalize case
			if (type == 'text' || type == 'password' || tag == 'textarea'){
			  	this.value = "";
			}else if (type == 'checkbox' || type == 'radio'){
			  	this.checked = false;
			}else if (tag == 'select'){
		    	this.selectedIndex = -1;
		    }
		});
	}
	
	function resetForm(){
		$("form").find(':input').not(':button, :submit, :reset').val('')
		.removeAttr('checked').removeAttr('selected');
	}

------------------------- 错误记录---------------------------------------------

/**
*什么是经验,遇到过的错误才是最大的经验!
*/

1、页面js error:"未结束的字符串常量";
    原因:js 方法中传传递的参数里,有html元素  及 回车换行符。(我曾经遇到的具体例子是:用户在备注的时候输入了回车,所以……。这种情况,要验证!)
    参数传递之前处理一下;保证没有html标签和回车换行符号。
    当然可能还有其它原因造成:http://yangfei520.blog.51cto.com/1041581/348278


2、现在的页面往往需要引入大量的js文件,之前项目中为了引入方便,写一个js文件a.js,这个文件里又引入其它js文件。这样在页面中只引入a.js就成了。

    最近发现由于项目越来越大,引入的js越来越多。造成页面非常臃肿。如果客户端那边网络不太很力,加载页面时要费很长时间,甚至导致用js处理的业务逻辑进行不下去!!!
    感叹一下:随着情况的不断变化,本来看着很方便的解决办法,又变成不方便。正应了太极的理念:变化是唯一不变的真理!顺势而为,方成大器!
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics