澳门新葡萄京官网首页JS脚本兼容性问题解决方案

本文跟我们享用了7种JS脚本分页样式,相信总有一款是相符你的啊

那边和大户人家大饱眼福一下缓慢解决JS脚本宽容的多少个小本领,关于JS脚本包容性我们首先个要考虑的标题应当是运作的平台是不是扶助顾客端脚本?平时的做法是将脚本中央饱含在一条HTML注释中。

赶紧先上海教室给大家采用一下——————运转作效果果——————-

澳门新葡萄京官网首页,解决JS脚本宽容的多少个小本领

实则作者挺中意最终一款的,亲,你呀?

对于存在JS脚本宽容性的地点,解决格局是本着分歧的阳台应用差别的特点或是用取代方式完毕,那是上策;但总有一点时候大家用上述措施不可能解决时,大家得以看下那么些难题是不是严重,假若不严重,那我们就能够忽视它。

为大家再享受达成JS脚本分页的代码,间接复制代码,运转就可以,紧紧抓住试试吧

1.运用HTML注释掉脚本

htmlheadtitle7种JS脚本分页代码/titlestylebody {font-size: 12px;}/* Pages Main Tyle */.pages { color: #000000; cursor: default; font-size: 10px; font-family: Tahoma, Verdana; padding: 3px 0px 3px 0px;}.pages .count, .pages .number, .pages .arrow { color: #000000; font-size: 10px; background-color: #F7F7F7; border: 1px solid #CCCCCC;}/* Page and PageCount Style */.pages .count { font-weight: bold; border-right: none; padding: 2px 10px 1px 10px;}/* Mode 0,1,2 Style (Number) */.pages .number { font-weight: normal; padding: 2px 10px 1px 10px;}.pages .number a, .pages .number span { font-size: 10px;}.pages .number span { color: #999999; margin: 0px 3px 0px 3px;}.pages .number a { color: #000000; text-decoration: none;}.pages .number a:hover { color: #0000ff;}/* Mode 3 Style (Arrow) */.pages .arrow { font-weight: normal; padding: 0px 5px 0px 5px;}.pages .arrow a, .pages .arrow span { font-size: 10px; font-family: Webdings;}.pages .arrow span { color: #999999; margin: 0px 5px 0px 5px;}.pages .arrow a { color: #000000; text-decoration: none;}.pages .arrow a:hover { color: #0000ff;}/* Mode 4 Style (Select) */.pages select, .pages input { color: #000000; font-size: 10px; font-family: Tahoma, Verdana;}/* Mode 5 Style (Input) */.pages .input input.ititle, .pages .input input.itext, .pages .input input.icount { color: #666666; font-weight: bold; background-color: #F7F7F7; border: 1px solid #CCCCCC;}.pages .input input.ititle { width: 70px; text-align: right; border-right: none;}.pages .input input.itext { width: 25px; color: #000000; text-align: right; border-left: none; border-right: none;}.pages .input input.icount { width: 35px; text-align: left; border-left: none;}.pages .input input.ibutton { height: 17px; color: #FFFFFF; font-weight: bold; font-family: Verdana; background-color: #999999; border: 1px solid #666666; padding: 0px 0px 2px 1px; margin-left: 2px; cursor: hand;}/stylescript language="JavaScript"!--function showPages(name) { //初始化属性 this.name = name; //对象名称 this.page = 1; //当前页数 this.pageCount = 1; //总页数 this.argName = 'page'; //参数名 this.showTimes = 1; //打印次数}showPages.prototype.getPage = function(){ //丛url获得当前页数,如果变量重复只获取最后一个 var args = location.search; var reg = new RegExp('[/&]' + this.argName + '=([^&]*)[&$]', 'gi'); var chk = args.match(reg); this.page = RegExp.$1;}showPages.prototype.checkPages = function(){ //进行当前页数和总页数的验证 if (isNaN(parseInt(this.page))) this.page = 1; if (isNaN(parseInt(this.pageCount))) this.pageCount = 1; if (this.page  1) this.page = 1; if (this.pageCount  1) this.pageCount = 1; if (this.page  this.pageCount) this.page = this.pageCount; this.page = parseInt(this.page); this.pageCount = parseInt(this.pageCount);}showPages.prototype.createHtml = function(mode){ //生成html代码 var strHtml = '', prevPage = this.page - 1, nextPage = this.page + 1; if (mode == '' || typeof(mode) == 'undefined') mode = 0; switch (mode) { case 0 : //模式1 (页数,首页,前页,后页,尾页) strHtml += 'span Pages: ' + this.page + ' / ' + this.pageCount + '/span'; strHtml += 'span '; if (prevPage  1) { strHtml += 'span title="First Page"/span'; strHtml += 'span title="Prev Page"/span'; } else { strHtml += 'span title="First Page"a href="javascript:'%20+%20this.name%20+%20'.toPage(1);"/a/span'; strHtml += 'span title="Prev Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20prevPage%20+%20');"/a/span'; } for (var i = 1; i = this.pageCount; i++) { if (i  0) { if (i == this.page) { strHtml += 'span title="Page ' + i + '"[' + i + ']/span'; } else { strHtml += 'span title="Page ' + i + '"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20i%20+%20');"[' + i + ']/a/span'; } } } if (nextPage  this.pageCount) { strHtml += 'span title="Next Page"/span'; strHtml += 'span title="Last Page"/span'; } else { strHtml += 'span title="Next Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20nextPage%20+%20');"/a/span'; strHtml += 'span title="Last Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20this.pageCount%20+%20');"/a/span'; } strHtml += '/spanbr /'; break; case 1 : //模式1 (10页缩略,首页,前页,后页,尾页) strHtml += 'span Pages: ' + this.page + ' / ' + this.pageCount + '/span'; strHtml += 'span '; if (prevPage  1) { strHtml += 'span title="First Page"/span'; strHtml += 'span title="Prev Page"/span'; } else { strHtml += 'span title="First Page"a href="javascript:'%20+%20this.name%20+%20'.toPage(1);"/a/span'; strHtml += 'span title="Prev Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20prevPage%20+%20');"/a/span'; } if (this.page % 10 ==0) { var startPage = this.page - 9; } else { var startPage = this.page - this.page % 10 + 1; } if (startPage  10) strHtml += 'span title="Prev 10 Pages"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20(startPage%20-%201)%20+%20');".../a/span'; for (var i = startPage; i  startPage + 10; i++) { if (i  this.pageCount) break; if (i == this.page) { strHtml += 'span title="Page ' + i + '"[' + i + ']/span'; } else { strHtml += 'span title="Page ' + i + '"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20i%20+%20');"[' + i + ']/a/span'; } } if (this.pageCount = startPage + 10) strHtml += 'span title="Next 10 Pages"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20(startPage%20+%2010)%20+%20');".../a/span'; if (nextPage  this.pageCount) { strHtml += 'span title="Next Page"/span'; strHtml += 'span title="Last Page"/span'; } else { strHtml += 'span title="Next Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20nextPage%20+%20');"/a/span'; strHtml += 'span title="Last Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20this.pageCount%20+%20');"/a/span'; } strHtml += '/spanbr /'; break; case 2 : //模式2 (前后缩略,页数,首页,前页,后页,尾页) strHtml += 'span Pages: ' + this.page + ' / ' + this.pageCount + '/span'; strHtml += 'span '; if (prevPage  1) { strHtml += 'span title="First Page"/span'; strHtml += 'span title="Prev Page"/span'; } else { strHtml += 'span title="First Page"a href="javascript:'%20+%20this.name%20+%20'.toPage(1);"/a/span'; strHtml += 'span title="Prev Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20prevPage%20+%20');"/a/span'; } if (this.page != 1) strHtml += 'span title="Page 1"a href="javascript:'%20+%20this.name%20+%20'.toPage(1);"[1]/a/span'; if (this.page = 5) strHtml += 'span.../span'; if (this.pageCount  this.page + 2) { var endPage = this.page + 2; } else { var endPage = this.pageCount; } for (var i = this.page - 2; i = endPage; i++) { if (i  0) { if (i == this.page) { strHtml += 'span title="Page ' + i + '"[' + i + ']/span'; } else { if (i != 1 && i != this.pageCount) { strHtml += 'span title="Page ' + i + '"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20i%20+%20');"[' + i + ']/a/span'; } } } } if (this.page + 3  this.pageCount) strHtml += 'span.../span'; if (this.page != this.pageCount) strHtml += 'span title="Page ' + this.pageCount + '"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20this.pageCount%20+%20');"[' + this.pageCount + ']/a/span'; if (nextPage  this.pageCount) { strHtml += 'span title="Next Page"/span'; strHtml += 'span title="Last Page"/span'; } else { strHtml += 'span title="Next Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20nextPage%20+%20');"/a/span'; strHtml += 'span title="Last Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20this.pageCount%20+%20');"/a/span'; } strHtml += '/spanbr /'; break; case 3 : //模式3 (箭头样式,首页,前页,后页,尾页) (only IE) strHtml += 'span Pages: ' + this.page + ' / ' + this.pageCount + '/span'; strHtml += 'span '; if (prevPage  1) { strHtml += 'span title="First Page"9/span'; strHtml += 'span title="Prev Page"7/span'; } else { strHtml += 'span title="First Page"a href="javascript:'%20+%20this.name%20+%20'.toPage(1);"9/a/span'; strHtml += 'span title="Prev Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20prevPage%20+%20');"7/a/span'; } if (nextPage  this.pageCount) { strHtml += 'span title="Next Page"8/span'; strHtml += 'span title="Last Page":/span'; } else { strHtml += 'span title="Next Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20nextPage%20+%20');"8/a/span'; strHtml += 'span title="Last Page"a href="javascript:'%20+%20this.name%20+%20'.toPage('%20+%20this.pageCount%20+%20');":/a/span'; } strHtml += '/spanbr /'; break; case 4 : //模式4 (下拉框) if (this.pageCount  1) { strHtml += 'select name="toPage" disabled'; strHtml += 'option value="0"No Pages/option'; } else { var chkSelect; strHtml += 'select name="toPage" onchange="' + this.name + '.toPage(this);"'; for (var i = 1; i = this.pageCount; i++) { if (this.page == i) chkSelect=' selected="selected"'; else chkSelect=''; strHtml += 'option value="' + i + '"' + chkSelect + 'Pages: ' + i + ' / ' + this.pageCount + '/option'; } } strHtml += '/select'; break; case 5 : //模式5 (输入框) strHtml += 'span '; if (this.pageCount  1) { strHtml += 'input type="text" name="toPage" value="No Pages" disabled="disabled"'; strHtml += 'input type="button" name="go" value="GO" disabled="disabled"/option'; } else { strHtml += 'input type="text" value="Input Page:" readonly="readonly"'; strHtml += 'input type="text" value="' + this.page + '" title="Input page" onkeypress="return ' + this.name + '.formatInputPage(event);" onfocus="this.select()"'; strHtml += 'input type="text" value=" / ' + this.pageCount + '" readonly="readonly"'; strHtml += 'input type="button" name="go" value="GO" onclick="' + this.name + '.toPage(document.getElementById(/'pageInput' + this.showTimes + '/').value);"/option'; } strHtml += '/span'; break; default : strHtml = 'Javascript showPage Error: not find mode ' + mode; break; } return strHtml;}showPages.prototype.createUrl = function (page) { //生成页面跳转url if (isNaN(parseInt(page))) page = 1; if (page  1) page = 1; if (page  this.pageCount) page = this.pageCount; var url = location.protocol + '//' + location.host + location.pathname; var args = location.search; var reg = new RegExp('([/&])' + this.argName + '=[^&]*[&$]', 'gi'); args = args.replace(reg,'$1'); if (args == '' || args == null) { args += '' + this.argName + '=' + page; } else if (args.substr(args.length - 1,1) == '' || args.substr(args.length - 1,1) == '&') { args += this.argName + '=' + page; } else { args += '&' + this.argName + '=' + page; } return url + args;}showPages.prototype.toPage = function(page){ //页面跳转 var turnTo = 1; if (typeof(page) == 'object') { turnTo = page.options[page.selectedIndex].value; } else { turnTo = page; } self.location.href = this.createUrl(turnTo);}showPages.prototype.printHtml = function(mode){ //显示html代码 this.getPage(); this.checkPages(); this.showTimes += 1; document.write('div /div'); document.getElementById('pages_' + this.name + '_' + this.showTimes).innerHTML = this.createHtml(mode); }showPages.prototype.formatInputPage = function(e){ //限定输入页数格式 var ie = navigator.appName=="Microsoft Internet Explorer"true:false; if(!ie) var key = e.which; else var key = event.keyCode; if (key == 8 || key == 46 || (key = 48 && key = 57)) return true; return false;}//--/script/headbodyp script language="JavaScript"!--var pg = new showPages('pg');pg.pageCount =12; // 定义总页数(必要)//pg.argName = 'p'; // 定义参数名(可选,默认为page)document.write('brShow Times: ' + pg.showTimes + ', Mood Default');pg.printHtml();document.write('brShow Times: ' + pg.showTimes + ', Mood 0');pg.printHtml(0);document.write('brShow Times: ' + pg.showTimes + ', Mood 1');pg.printHtml(1);document.write('brShow Times: ' + pg.showTimes + ', Mood 2');pg.printHtml(2);document.write('brShow Times: ' + pg.showTimes + ', Mood 3 (only IE)');pg.printHtml(3);document.write('brShow Times: ' + pg.showTimes + ', Mood 4');pg.printHtml(4);document.write('brShow Times: ' + pg.showTimes + ', Mood 5');pg.printHtml(5);//-- /script/p/body/html

关于JS脚本包容性大家首先个要思考的标题应当是运作的平台是不是援助客商端脚本?平日的做法是将脚本大旨包罗在一条HTML注释中:

如上正是以上就是为我们大饱眼福的js脚本分页代码,希望大家能够赏识。

<scriptlanguagescriptlanguage="javascript"> <!--  document.write(newDate());  //--> </script>  

这样不辅助JS脚本的浏览器会忽视<script>和</script>标签并把别的轮代理公司码当做一条HTML注释管理,而扶持脚本的浏览器则把”<!–“那句当作一条HTML注释语句,其余语句符合规律施行,HTML注释结尾”–>”用”//”进行单行注释。

2.性格、平台检验

当大家要动用的特色和平台有关时,就得先实行检查实验再选拔,检查测试的法子有二种:一种是直接检验平台是不是帮衬该特性,另一种是检验平台项目再选择相应的特征。代码如下:

<scriptlanguagescriptlanguage="javascript"> <!--  //a.检测是否支持特性  if(s.split){  a=s.split(",");//支持,直接使用  }else{  a=s.mysplit(",");//不支持,使用替代方法  }  //b.平台检测  if(navigator.appName.indexOf("Microsoft")!=-1){  //使用IE支持的特性  }  //--> </script>  

3.替代?忽略?停止?

对此存在JS脚本兼容性的地点,消亡方法是针对不一致的平台利用分歧的特色或是用代替情势完结,这是上策;但总有一部分时候我们用上述格局无法缓和时,大家能够看下那几个难点是不是严重,如若不严重,那我们就能够忽视它,举个例子贰个风味在Netscape2上无效,但现行大概没人使用Netscape2了,那大家就概况它;假诺不能够解决但难题又相比较严重,那大家就应下不为例脚本的运作,并明确报告客户发生的主题材料!
 

发表评论

电子邮件地址不会被公开。 必填项已用*标注