日期:2014-05-16  浏览次数:20488 次

javascript搜集
var newwin = null
//-------------------------------------------------弹出窗口(地址,宽,高)
function newwindow(to,w,h)
{
if (!newwin || newwin.closed)
{
newwin=window.open(to,"indexww","width="+w+",height="+h+",scrollbars")
}
else
{
newwin.close()
newwin=window.open(to,"indexww","width="+w+",height="+h+",scrollbars")
}
newwin.focus()
}

//--------------------------------------------------检验字符
function ischar(s)
{
var errorChar;
var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`";

if ( s == "" )
{
alert("请您输入内容!")
return false;
}

if ( isWhitespace(s) )
{
alert("输入的字符中不能包含空格符,请重新输入!");
return false;
}
errorChar = isCharsInBagEx( s, badChar)
if (errorChar != "" )
{
alert("您输入的字符" + s+"是无效的,\n\n请不要在字符中输入" + errorChar + "!\n\n请重新输入合法的字符!" );
return false;
}


return true;
}

//---------------------------------------------------检验用户名
function isUserName(s)
{
var errorChar;
var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`";
if (isEmpty(s))
{
alert(" 请输入用户名!");
return false;
}
if ( isWhitespace(s) )
{
alert(" 输入的用户名中不能包含空格符,请重新输入?quot;);
return false;
}
errorChar = isCharsInBagEx( s, badChar)
if (errorChar != "" )
{
alert("您输入的用户名" + s+"是无效的用户名,\n\n请不要在用户名中输入字符" + errorChar + "!\n\n请重新输入合法的用户名!" );
return false;
}
if (s.length<1 || s.length>20){
alert("用户名必须在1至 20个字符之间")
return false
}

return true;
}


//公用函数

//---------------------------------------------------字符是否在S中
function isCharsInBag (s, bag)
{
var i;
// Search through string's characters one by one.
// If character is in bag, append to returnString.

for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) return false;
}
return true;
}

function isEmpty(s)
{
return ((s == null)||(s.length == 0));
}

//----------------------------------------------------空格判断
function isWhitespace (s)
{
var whitespace = " \t\n\r";
var i;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (whitespace.indexOf(c) >= 0)
{
return true;
}
}

return false;
}

//----------------------------------------------------闰年判断
function isleapyear(thisyear)
{
return(((thisyear%4==0) && (thisyear%100!=0)) || (thisyear%400==0))

}

//----------------------------------------------------除S以外的字符
function isCharsInBagEx (s, bag)
{
var i,c;
// Search through string's characters one by one.
// If character is in bag, append to returnString.
for (i = 0; i < s.length; i++)
{
c = s.charAt(i);
if (bag.indexOf(c) > -1)
return c;
}
return "";
}

//----------------------------------------------------是否选择单选按钮
function radioselected(radioBth)
{
for(i=0;i<radioBth.length;i++)
{
if(radioBth[i].checked)
return true
}
return false
}

//----------------------------------------------------年份判断
function isYear(s)
{
var Today=new Date()
thisYear=Today.getYear()
var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&`";
var len = s.length;
if (isEmpty(s)){
alert("必须输入年份")
return false;
}
if ( isCharsInBag( s, badChar)){
alert("年份输入非法")
return false;
}
if ((len!=4)){
alert("年份是四位!");
return false;
}
if(!isCharsInBag (s, "0123456789")){
alert("请检查一下您输入的年份是否为数字!");
return false;