日期:2014-05-16 浏览次数:20395 次
几个常用的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(); }?
?