根据ID获取元素function io(oid){return document.getElementById(oid)}
/*JSON*/
function getjsonphp(retu,ojl){
var xmlHttp;
try{
xmlHttp = new XML
HTML文字滚动代码
<marquee>滚动文字</marquee>
水平滚动:
<marquee direction="left" align="bottom" height="25" width="100%" onmouseout="this.start()" onmouseover="this.stop()" scrollamount="2" scrolldelay="1">水平滚动字幕内容</marquee>
垂直滚动:
<marquee direction="up" height="200" onmouseout="this.start()" onmouseover="this.stop()" scrollAmount="1" scrollDelay="1">垂直滚动字内容</marquee>
去掉html标签的js
<script> function delHtmlTag(str){ return str.replace(/<[^>]+>/g,"");//去掉所有的html标记 } var str = "<span style='display:none;'>This is test</span><img src=''>ss</img><strong></strong><br/>"; str = delHtmlTag(str); alert(str); </script>
为了一个title去html标签所做的修改:
function delHtmlTag(str, obj){ var title = str.replace(/<[^>]+>/g,"");//去掉所有的html标记 if(title.length > 300) { title = title.substring(0,300); } obj.title = title; }
去掉字符串前后所有空格:
function Trim(str){ return str.replace(/(^\s*)|(\s*$)/g, ""); }
去掉字符串中所有空格(包括中间空格,需要设置第2个参数为:g)
function Trim(str,is_global){ var result; result = str.replace(/(^\s+)|(\s+$)/g,""); if(is_global.toLowerCase()=="g"){ result = result.replace(/\s/g,""); } return result; }
js 的replace方法将字符串中的 全部替换为空字符串
<script language="javascript"> var test="this is a test"; test=test.replace(/ /ig, ""); alert(test); </script>
根据ID获取元素
function io(oid){return document.getElementById(oid)} /*JSON*/ function getjsonphp(retu,ojl){ var xmlHttp; try{ xmlHttp = new XMLHttpRequest(); }catch(e){ try{ xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ return false; } } } xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4 && xmlHttp.status==200){// var strml = xmlHttp.responseText; var objht = ''; if(ojl == 0){ objht = eval("(" + strml + ")"); hpayqu(decodeURI(objht.hm)); } if(ojl == 1){ objht = eval("(" + strml + ")"); koextb(decodeURI(objht.hm)); } if(ojl == 2){ objht = eval("(" + strml + ")"); if(decodeURI(objht.hm) == 'k'){ kztmjh(); } } if(ojl == 3){ objht = eval("(" + strml + ")"); plist(objht); } }; } if(retu != null){ xmlHttp.open("POST", retu, true); xmlHttp.send(); } }
倒计时只执行一次
kmj = setTimeout(function(){ 执行代码 },1000); //终止 clearTimeout(kmj);
倒计时只执无限执行
kmj = setInterval("sskozhi()", 1000); //终止 clearInterval(kmj);
分割字符串
var temv = str.split(":");
编码解码字符串
//编码 encodeURI(rm) //解码 decodeURI(rm)
换算时间
function hnusaime(dem){ var iDay,iHour,iMinute,iSecond; var sDay="",sHour="",sMinute="",sSecond="",sTime=""; if(dem >= 0){//-倒计时的值>=0 iDay = parseInt(iTime/24/3600);//计算-单位秒 if(iDay > 0){ if(zshuxz(iDay) < 2){ iDay = '0' + iDay; } sDay = iDay + " 天 "; } iHour = parseInt((iTime/3600)%24); if(iHour > 0){ if(zshuxz(iHour) < 2){ iHour = '0' + iHour; } sHour = iHour + ":"; } iMinute = parseInt((iTime/60)%60); if(iMinute > 0){ if(zshuxz(iMinute) < 2){ iMinute = '0' + iMinute; } sMinute = iMinute + ":"; } iSecond = parseInt(iTime%60); if(iSecond >= 0){ if(zshuxz(iSecond) < 2){ iSecond = '0' + iSecond; } sSecond = iSecond + ""; } sTime = sDay + sHour + sMinute + sSecond; } return sTime; }
倒计时
function rmaintime(){ var iDay,iHour,iMinute,iSecond; var sDay="",sHour="",sMinute="",sSecond="",sTime=""; if(iTime >= 0){//-倒计时的值>=0 iDay = parseInt(iTime/24/3600);//计算-单位秒 if(iDay > 0){ if(zshuxz(iDay) < 2){ iDay = '0' + iDay; } sDay = iDay + " 天 "; } iHour = parseInt((iTime/3600)%24); if(iHour > 0){ if(zshuxz(iHour) < 2){ iHour = '0' + iHour; } sHour = iHour + ":"; } iMinute = parseInt((iTime/60)%60); if(iMinute > 0){ if(zshuxz(iMinute) < 2){ iMinute = '0' + iMinute; } sMinute = iMinute + ":"; } iSecond = parseInt(iTime%60); if(iSecond >= 0){ if(zshuxz(iSecond) < 2){ iSecond = '0' + iSecond; } sSecond = iSecond + ""; } if(sMinute == ''){ sMinute = '00:'; }else{ sMinute = sMinute; } if(sSecond == ''){ sSecond = '00:'; }else{ sSecond = sSecond; } sTime = sDay + sHour + sMinute + sSecond; if(iTime==0){//时间到 clearTimeout(ime); //$$("yibftm").innerHTML = sTime; var drct = 'ction/qingqiucl.php?qiqe=cdzt&tags='+ rm +'&page='+ iTime +'&gshm='+ ke; getjsonphp(drct,90); huoqxys(); return false; }else{//时间到-否则继续 ime = setTimeout("rmaintime()",1000); iTime = iTime - 1; //$$("yibftm").innerHTML = sTime; var drct = 'ction/qingqiucl.php?qiqe=cdzt&tags='+ rm +'&page='+ iTime +'&gshm='+ ke; getjsonphp(drct,90); return false; }//时间到-END //iTime=iTime-1; }else{//--倒计时的值>=0否则-倒计时结束 sTime = "00:00"; }//-倒计时的值>=0-END //$$("yibftm").innerHTML = sTime; var drct = 'ction/qingqiucl.php?qiqe=cdzt&tags='+ rm +'&page='+ iTime +'&gshm='+ ke; getjsonphp(drct,90); }
字符串长度
function zshuxz(txv){ var zw=yw = 0; txv = txv.toString(); for (i = 0; i < txv.length; i++) { var leg = txv.charCodeAt(i);//ASCII if (leg > 255) { zw += 1; //中文 } else { yw += 1; //英文 } } return eval(zw + yw); }
写入数组
var etry = []; etry.push('9999999999999');
获取最后一个数组
var zuhy = etry.pop();
删除最后一个数组
etry.splice(-1,-1); //添加一个元素: var arr = new Array(6) arr[0] = "George" arr[1] = "John" arr[2] = "Thomas" arr[3] = "James" arr[4] = "Adrew" arr[5] = "Martin" document.write(arr + "<br />") arr.splice(2,0,"William") document.write(arr + "<br />")
删除指定数组
etry.remove(etry.length); Array.prototype.remove=function(dx){ if(isNaN(dx)||dx>this.length){return false;} for(var i=0,n=0;i<this.length;i++){ if(this[i]!=this[dx]){ this[n++]=this[i]; } } this.length-=1; }
获取时间戳
var sjco = new Date().getTime();
变成算式
var peg = 1; var kkk = eval(parseFloat(peg) + 1);
将字符串变成整数
var fnwh = parseInt(fnbjo.clientWidth);
替换
var rcht = srcd.replace('nor',"sel");
上一篇:常用基本PHP语句二
下一篇:百度快照删除整理链接
评论列表
发表评论
热评文章
相关阅读