幾個JS小代碼

1.回車控制

var keyc=window.event.keyCode;
if(keyc==13)
{
	//自己的操作
}

2.獲得與數據庫一樣格式的時間串

function nowTime()
	{
		var now=new Date();

		var timeStr=now.getYear()+"-";
		if(now.getMonth()<9)
		{
			timeStr += "0"
			timeStr += now.getMonth()+1+"-";
		}else
		{
			timeStr += now.getMonth()+1+"-";
		}
		if(now.getDate()<10)
		{
			timeStr +="0"+now.getDate();
		}else
		{
			timeStr += now.getDate();
		}	
		if(now.getHours()-0<10)
		{
			timeStr +=" 0"+now.getHours();
		}else
		{
			timeStr +=" "+now.getHours();
		}
		if(now.getMinutes()-0<10)
		{
			timeStr +=":0"+now.getMinutes();
		}else
		{
			timeStr +=":"+now.getMinutes();
		}
		if(now.getSeconds()-0<10)
		{
			timeStr +=":0"+now.getSeconds()
		}else
		{
			timeStr +=":"+now.getSeconds()
		}
		return timeStr;
	}

3.全屏局中open

window.open("<c:url value='/"+url_+"'/>","","toolbar=0,location=0,scrollbars=1,resizable=1,width="+(screen.availWidth-20)+",height="+(screen.availHeight-30)+",top=0,left=0")

4.js對文字進行編碼涉及3個函數:escape,encodeURI,encodeURIComponent,

相應3個解碼數:unescape,decodeURI,decodeURIComponent


5.獲得js對象的內容

var aaaa;
for(var a in obj)
{
  aaaa+=a+"  :  "+json[a]+"<br/>"
}
//document.write(aaaa);
//alert(aaaa);

6.iframe 內 調用外部方法 和 iframe外 調用iframe內的

//iframe中
window.parent.myMethod();

//iframe中
window.parent.setIframeDom(window);

//iframe外
var iframeObj;
function setIframeDom(obj)
{
	iframeObj=obj;
}

//例子
function exportToExcelO()
{
	iframeObj.exportToExcel();
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章