[javascript]

 动态创设正则表明式

原来状态:
图片 1 
鼠标经过:
图片 2 

复制代码 代码如下:

复制代码 代码如下:

复制代码 代码如下:

<script type=”text/javascript”>
function clickIE4(){
        if (event.button==2){
                return false;
        }
}

 new RegExp( Expr.match[ type ].source +
(/(?![^\[]*\])(?![^\(]*\))/.source) )

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“;
<html xmlns=”;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″
/>
<title>无标题文书档案</title>
<script language=”javascript”
src=”;
<script language=”javascript”>
$(function(){
var offsetX=20-$(“#imgtest”).offset().left;
var offsetY=20-$(“#imgtest”).offset().top;
var size=1.2*$(‘#imgtest ul li img’).width();
$(“#imgtest ul li”).mouseover(function(event) {
var $target=$(event.target);
if($target.is(‘img’))
{
$(“<img id=’tip’ src='”+$target.attr(“src”)+”‘>”).css({
“height”:size,
“width”:size,
“top”:event.pageX+offsetX,
“left”:event.pageY+offsetY,
}).appendTo($(“#imgtest”));
}
}).mouseout(function() {
$(“#tip”).remove();
}).mousemove(function(event) {
$(“#tip”).css(
{
“left”:event.pageX+offsetX,
“top”:event.pageY+offsetY
});
});
})
</script>
<style type=”text/css”>
img{ height:262px; width:400px; position:absolute; border:5px solid
#FFF;}
#imgtest{ height:auto;width:840px; margin:0 auto; position:absolute;
}
#imgtest ul{ position:relative;width:840px; height:auto;
background:#00F;}
#imgtest ul li{ position:relative; height:276px; width:410px;
list-style:none; float:left; margin:3px; border:1px solid #999;}
</style>
</head>
<body>
<div id=”imgtest”>
<ul>
<li><img src=”img/photo1.jpg” /></li>
<li><img src=”img/photo2.jpg” /></li>
<li><img src=”img/photo3.jpg” /></li>
<li><img src=”img/photo4.jpg” /></li>
</ul>
</div>
</body>
</html>

function clickNS4(e){
        if (document.layers||document.getElementById&&!document.all){
                if (e.which==2||e.which==3){
                        return false;
                }
        }
}

根源sizzle,动态创设正则时,那样做幸免了字符转义。

鼠标经过: 复制代码 代码如下: !DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“” ht…

function OnDeny(){
        if(event.ctrlKey || event.keyCode==78 && event.ctrlKey ||
event.altKey || event.altKey && event.keyCode==115){
                return false;
        }
}

更加灵活和高超的数字补零

if (document.layers){
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown=clickNS4;
        document.onkeydown=OnDeny();
}else if (document.all&&!document.getElementById){
        document.onmousedown=clickIE4;
        document.onkeydown=OnDeny();
}

复制代码 代码如下:

document.oncontextmenu=new Function(“return false”);
</script>

function prefixInteger(num, length) {
    return (num / Math.pow(10, length)).toFixed(length).substr(2);
}

<script type=”text/javascript”>
function clickIE4(){
        if (event.button==2){
                return false;
        }
}

 取数组的最大和最小值

function clickNS4(e){
        if (document.layers||document.getElementById&&!document.all){
                if (e.which==2||e.which==3){
                        return false;
                }
        }
}

复制代码 代码如下:

function OnDeny(){
        if(event.ctrlKey || event.keyCode==78 && event.ctrlKey ||
event.altKey || event.altKey && event.keyCode==115){
                return false;
        }
}

Math.max.apply(Math, [1,2,3]) //3
Math.min.apply(Math, [1,2,3]) //1

if (document.layers){
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown=clickNS4;
        document.onkeydown=OnDeny();
}else if (document.all&&!document.getElementById){
        document.onmousedown=clickIE4;
        document.onkeydown=OnDeny();
}

产生优异的专擅字符串

document.oncontextmenu=new Function(“return false”);
</script>

复制代码 代码如下:

] 复制代码 代码如下: script
type=”text/javascript” function clickIE4(){ if (event.button==2){ return
false; } } function clickNS4(e){ if (document.layers||docume…

Math.random().toString(16).substring(2); //8位
Math.random().toString(36).substring(2); //16位

 获取时间戳

相对于
var timeStamp = (new Date).getTime();
正如方式更有益于:

复制代码 代码如下:

var timeStamp = Number(new Date);

 转变为数值并取整

发表评论

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