您的位置:首页 > Web前端 > JavaScript

Js

2015-07-18 17:31 579 查看

1. 关闭当前窗口

   <a href="javascript:window.opener=window.self;window.close()"></a>

2. 验证可以输入多少个汉字(下面表示输入的汉字大于20个)

    str.replace(/[^\x00-\xff]/g,'xx').length > 50

//把原本录入是换行的展示时也换行

var specialRequireVal = (result[i]["value"]).replace(/\n/g,"<BR>");

<% request.setAttribute("vEnter", "\n");  %>

${fn:replace(item.value,vEnter,"<BR>") }

cellTd.style.textAlign="left";

//验证是否有中文

    function isChiness(str){

        if(/.*[\u4e00-\u9fa5]+.*$/.test(str)) {

             //alert("不能含有中文!");

             return false;

         }

         return true;

    }

function IE_Flash()

{

try

{

var swf=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");

alert("已安装插件");

}

catch(e)

{

alert("没有安装插件");

}

}

//FireFox,Chrome中判断是否安装插件

function FF_or_Chrome_Flash()

{

var swf=navigator.plugins["Shockwave Flash"];

(swf)?alert("已安装插件"):alert("没有安装插件");

}

//js定位到页面的某个锚点

location.hash="maoDian";

window.location

属性                  描述

hash                设置或获取 href 属性中在井号“#”后面的分段。

host                 设置或获取 location 或 URL 的 hostname 和 port 号码。

hostname      设置或获取 location 或 URL 的主机名称部分。

href                  设置或获取整个 URL 为字符串。

pathname      设置或获取对象指定的文件名或路径。

port                  设置或获取与 URL 关联的端口号码。

protocol          设置或获取 URL 的协议部分。

search            设置或获取 href 属性中跟在问号后面的部分。

_value = _value.htmlEncode();

 _value = _value.replace(/ /g, " "); //页面显示的时候把空格也显示出来

$("#bag option").each(function(){  

if($(this).text()=="xxx"){  

$(this).attr("selected",true)  

//$(this).attr("selected","selected")两者都可以选中  

}

// 中文字两个字节

jQuery.validator.addMethod(

    "byteRangeLength",

    function(value, element, param) {

        var length = value.length;

        for(var i = 0; i < value.length; i++){

            if(value.charCodeAt(i) > 127){

                length++;

            }

        }

        return this.optional(element) || (length >= param[0] && length <= param[1]);   

    },

    $.validator.format("请确保输入的值在{0}-{1}个字节之间(一个中文字算2个字节)")

);

// 邮政编码验证   

jQuery.validator.addMethod("isZipCode", function(value, element) {   

    var tel = /^[0-9]{6}$/;

    return this.optional(element) || (tel.test(value));

}, "请正确填写您的邮政编码");

 window.onload = function () {

            $("#main").css("width", $(window).width() - 210);

            $("#main").css("height", $(window).height() - 108);

            $("#mainHidder").css("height", $(window).height() - 108);

            $("#menu").css("height", $(window).height() - 108);

        }

        window.onresize = function () {

            $("#main").css("width", $(window).width() - 210);

            $("#main").css("height", $(window).height() - 108);

            $("#mainHidder").css("height", $(window).height() - 108);

            $("#menu").css("height", $(window).height() - 108);

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: