在zet学习笔记

1.Jqery: function convertOperate(col,id,state){ //alert('test'); var num=new Array("0","1","3"); var msg=new Array("草稿","待审核","审核不通过"); for(var i=0;i<num.length;i++){ //alert(num[i]+'<----->'+state); if(num[i]==state){ $("#div_").show(); ---->注意 } } return col['operate']; } function convertState(col){ var num=new Array("0","1","2","3","4"); var msg=new Array("草稿","待审核","审核通过","审核不通过","已作废"); for(var i=0;i<num.length;i++){ if(num[i]==col['status']) col['status']=msg[i]; } return col; } 显示列就用col 2.循环遍历select: var selectObj = $("#invtrades option"); for(var i=0;i<selectObj.length;i++) { if(selectTrades==selectObj.get(i).value) { selectObj.get(i).selected=true; } } 3.手机正则表达式: if(mobilePhone!=null&&mobilePhone!=""){ var reg=/^(/d{2,3}-)?1[3|5|8]/d{9}?$/; if(!reg.test(mobilePhone)){ ------}注意:和Java不一样reg.matcher(reg) alert("请输入手机号码!"); return validator; } function selectMenu(menuid,subtitleid,submenuid) { var menuId = "#leftMenu"; $(menuId).find("dd").hide(); $(menuId).find("dt").removeClass("selected"); var menuObj = document.getElementById(menuid); var ddObj = menuObj.getElementsByTagName("dd"); ddObj[0].style.display ="block"; for(i=0;i<ddObj.length;i++) { ddObj[i].style.display = ""; } document.getElementById(subtitleid).className="selected"; document.getElementById(submenuid).className ="focus"; } 1. 把提示信息放到input的后面 $("#historyFinance").after("<span class='error_info' style="color:red;" mce_style="color:red;">请输入历史财务数据!</span>"); 2.Jquery聚焦:$("#marketAnalysis").focus(); 3.jquery单项绑定:(eval) for(var i=0;i<props.length;i++){ var propValue=eval("invFund."+props[i]); $("#"+props[i]+"").html(propValue); } 4. value+=("<li><a target='_blank' onClick=/"callSid('hitService','"+proList[i].projectId+"')/" href="projectDetail.html?projectId="+proList[i].projectId+"" mce_href="projectDetail.html?projectId="+proList[i].projectId+"">"+proList[i].projectTitle+"</a></li>"); 5.map用法: 原数组中大于 0 的元素加 1 ,否则删除。 $.map( [0,1,2], function(n){ return n > 0 ? n + 1 : null; }); 6.<a href="javascript:getOperater('${appId}','${keyWords}' );" mce_href="javascript:getOperater('${appId}','${keyWords}' );" 7. var updateToDate = getCalendarValue("toDate"); var txtType1 = $("#appType1 option:selected").text(); 8:截取字符串: if(obj.title.length > 10) { obj.title = obj.title.substring(0,20); obj.title += "..."; } 9.图片超链接: //随机验证码 function refreshValidCode() { var imgObj = document.getElementById("validCodeImg"); var time = new Date().getTime(); imgObj.src = "../../../getValidCodeServlet?time=" + time; } 10.手机正则表达式 var email = /^/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/; 11.得到上传文件的输入框的值: Var baPath=document.getElementById("div_certificateAttPath").previousSibling.value; 12.对select进行遍历: function getCertType(ret) { var options = new Array(); options.push("<option value='all'>全 部</option>"); for(var i=0;i<ret.length;i++) { options.push("<option value='" + ret[i].dataName + "'>" + ret[i].dataName + "</option>"); } $("#certificateType").html(options.join("")); } 13.判断是否是整数:if(!isInteger(amount.value)){ 14. if(!(/^[-/+]?/d+$/.test(amount.value))){ alert('充值金额只能是整数'); return; 15. //获取输入字符串的长度 function getLengthOfChar(char) { var len = 0; for (var i = 0; i < char.length; i++) { if (char.charCodeAt(i)>127 || char.charCodeAt(i)==94) { len += 2; } else { len ++; } } return len; } 16. //验证输入密码字符的合法性 function funcPasswordValid(myPassword) { for (var i = 0; i < myPassword.length; i++) { if (!(myPassword.charCodeAt(i) <= 126 && myPassword.charCodeAt(i) >= 33)) { return false; } } return true; } 17. //隐藏div function hideTabs() { $("li[name='tdTab'][className != 'on']").each( function() { $('#'+this.childNodes[0].href.split("#")[1]).hide(); } ); } 18.//tabs 选择 function selectTab(o) { if("on" != o.className){ $("li[name='tdTab']").each(function(){$(this).removeClass('on')}; hideTabs(); $(o).addClass('on'); $('#'+o.childNodes[0].href.split("#")[1]).show() ; } } 19.验证时候有特殊字符: var re_title = /[-_/~!@#……¥/$%/^&/*/./(/)/[/]/{/}<>/?/////'/"]/; if(re_title.test($("#msgTitle").val())){ $("#msgTitle").next("span").next("span").css("color","red"); $("#msgTitle").focus(); return true; } 20.Jquery用法: $("#messageStatus").html(obj.msgStatus=="0"?"未阅读":"已阅读"); $("#receiveDate").html(formatDate(new Date(obj.receiveDate), "yyyy-MM-dd HH:mm:ss")); 21.对输入的字符做判断: (1).<td><textarea id="textContainer1" name="salutatory" cols="75" rows="10" onkeyup="checkMaxInput(this,100,'remLen');" onfocus="checkMaxInput(this,100,'remLen');" >

剩余字数(包括标点),不超过 个字符(中文算2个字符)

(2)用Jquery对输入的文本框进行时刻校验: function checkMaxInput(_this,maxleng,leftInforId) { var left=document.getElementById(leftInforId); var len=_this.value.replace(/[^/x00-/xff]/gi,'xx').length; var remainnum =parseInt(maxleng)-len; left.value = remainnum; if(remainnum < 0) { if(_this.value.length!=len) { if((len-_this.value.length)>(maxleng/2)) { _this.value=_this.value.substring(0,maxleng/2); } else { _this.value=_this.value.substring(0,maxleng-(len-_this.value.length)); } }else{ _this.value=_this.value.substring(0,maxleng); } left.value=0; return; } } 22.url传递值 window.location.href='audit.html?ids='+ids+'&type='+type; window.open("viewSendMsg.html?msgId="+id); 23.Java中面向对象的查询: if(dao.createCriteria(AppScore.class).add(Expression.eq("memberId", memberId)).add(Expression.eq("appId", appId)).list().isEmpty()) 另一个经常碰到的任务是在没有被jQuery覆盖的DOM元素上call一些方法,想像一个在你用AJAX方式成功提交后的reset: $(document).ready(function() { // use this to reset a single form $("#reset").click(function() { $("#form")[0].reset(); }); }); 24.给img标签赋值: imgsrc = "../../../images/1-star.gif "; $("img[id=imgs]").attr("src",imgsrc); 25.找标签(在标签里找其他的元素) $('div table tr').find(".element").html("---------ddd").css("border","1px solid #ccc").css("color","blue"); 26.由jQuery对象转换成Dom var s = $('#iconStandPath').find('img')[0]; $(s).attr("src",ret.iconStandPath); 27.图片的改变: var s = $('#iconStandPath').find('img')[0]; //var src = "../../.." + ret.iconStandPath + "" //var src = ""; //$('#iconStandPath').html(src); $(s).attr("src",ret.iconStandPath).css('width',220).css('height',300); 28.hql rownum String sql = "select s.*,rownum from (select t.APP_ID,t.APP_NAME,t.ICON_SMALL_PATH,t.VIEW_COUNT,t.DOWNLOAD_COUNT,t.RELEASE_TIME,t.MEMBER_ID,t.SUBMIT_TIME from app_application_info t where t.app_status='4' order by VIEW_COUNT desc) s where rownum<7 "; 29.hibernate数据查询: List paramValues = new ArrayList(); list = dao.getAppSql(sql,paramValues); for(int i=0;i (图片)alt=”图片提示语句” 32.QBC查询(带有查询参数): AppFavorite favorite = (AppFavorite) dao.createCriteria(AppFavorite.class) .add(Expression.eq("appId", o.getAppId())) .add(Expression.eq("memberId", SysUtils.getCurrUserID(RIAContext.getCurrentInstance().getRequest()))) .uniqueResult(); 32.优化hql: 对于帖子1)我建议优化一下hql from Employee e where e.salary is null or empty(e.salary) select count(e.salary) from Employee e where e=:e; 开启二级缓存:(setHint) Query query = entityManager.createQuery("from User u").setHint("org.hibernate.readOnly", true); Hibernate: return dao.createCriteria(AppApplicationInfo.class) .add(Property.forName("appType1").in(new String[]{"应用软件","应用主题","应用游戏"})).setMaxResults(2) .addOrder(Property.forName("viewCount").asc()).list();

你可能感兴趣的:(JavaScript,jquery,Hibernate,function,正则表达式,application)