日期:2014-05-16  浏览次数:20393 次

一些常用的JS代码

?function execServlet(servletUrl,callStyle,str){
??var ret = "";
??if(!callStyle) callStyle = "GET";
??try {??
??? ?xh = new ActiveXObject("Microsoft.XMLHTTP");
??? ?xh.open( callStyle,servletUrl,false);
??? ?xh.send(str);
?? ??ret =? xh.responseText;
??? ?}catch (error){
??? ?}
?? ?return ret;
?}
?
?function changeCinema(obj){
??var cinemaSelect=document.getElementById("cinemaNameSearch");
??var rnd = Math.random();
??var url="<%=contextPath%>/infoservice/filmScheduleAction.action?action=chanegCinema&&cityCodeSearch="+obj.value;
??var ret=execServlet(url,'GET',"");
??var str=ret.split("&&");
??cinemaSelect.innerHTML="";
??cinemaSelect.options.add(new Option("-请选择-","")); ?
??for(var i=0;i<str.length&&""!=str[i];i++){
???cinemaSelect.options.add(new Option(str[i],str[i]));
??}?
?}

//********ajax级联下啦列表,***********//

function toPage(action){//分页查询?
???var vPageNo=document.getElementById("pageNo").value;
???var vPages=document.getElementById("pages").value;
???if(vPageNo==null||vPageNo==''){
????vPageNo=1;
???}else{
????vPageNo=parseInt(vPageNo);
???}
???if(vPages==null||vPages==''){
????vPages=1;
???}else{
????vPages=parseInt(vPages);
???}
??if (action == "listFirst") {
???if(vPageNo==1){
????alert('已经是第一页');
????return false;
???}
???form1.pageNo.value="1";
??} else if (action == "listNext") {
???if(vPageNo<vPages){
????vPageNo=vPageNo+1;
????form1.pageNo.value=vPageNo;
???}else{
????alert('已经是最后一页');
????return false;
???}
??} else if (action == "listPrev") {
???if(vPageNo>1){
????vPageNo=vPageNo-1;
????form1.pageNo.value=vPageNo;
???}else{
????alert('已经是第一页');
????return false;
???}
??} else if (action == "listLast") {
???if(vPageNo==vPages){
????alert('已经是最后一页');
????return false;
???}
???form1.pageNo.value=vPages;
??} else if (action == "listSpec") {
???if (form1.pageNo.value == "" || form1.pageNo.value == null) {
????alert("您没有输入页号!");
????form1.pageNo.value="";
????return "false";
???} else if (parseInt(form1.pageNo.value)<1||parseInt(form1.pageNo.value)>vPages){
????alert("您输入的页号不存在,请重新输入!");
????form1.pageNo.value="";
????return "false";
???}
??}
??form1.submit();?
?}

//*******分页查询********//
function checkLength(msg,obj,length){
??var v=getBytesCount(obj);
??if (v>length){
???alert(msg+'内容超长!');
???obj.value=obj.value.substring(0,length);
???return false;
??}
??if(parseInt(obj.value)>24){
???alert(msg+'不能大于24!');
???obj.value=obj.value.substring(0,1);
???return false;
??}
??return true;
}
?function getBytesCount(obj){//获取文本字节数
??var str=obj.value;
??? if (str == null){???
??????? return 0;???
?? ? }else{???
??????? return (str.length + str.replace(/[\u0000-\u00ff]/g,"").length);???
?? ? }???
?}?
//*****简单校验*****//