JavaScript

有用的JS判断html教程

时间:2013-6-19 22:25:28  作者:WPF之家  来源:http://www.wpf123.com  查看:289  评论:0
内容摘要:function OrtTrimString (strVal){var reVal;var strTmp;strTmp = strVal + "";if (strTmp.length == 0)return (strTmp);reVal = /^(\s| )*...

function OrtTrimString (strVal)
{
var reVal;
var strTmp;
strTmp = strVal + "";
if (strTmp.length == 0)
return (strTmp);
reVal = /^(\s| )*/;
strTmp = strTmp.replace (reVal, '');
reVal = /(\s| )*$/;
return (strTmp.replace (reVal, ''));
}

-------------------------------

function OrtHtmlFormat (strVal)
{
var reVal;
var strTmp;
reVal = /</g;
strTmp = strVal.replace (reVal, "&lt;");
reVal = />/g;
strTmp = strTmp.replace (reVal, "&gt;");
reVal = /"/g;
strTmp = strTmp.replace (reVal, "&quot;");
return (strTmp);
}

-------------------------------

function OrtUrlStringFormat (strVal)
{
var reVal;
var strTmp;
reVal = /%/g;
strTmp = strVal.replace (reVal, "%25");
reVal = /&/g;
strTmp = strTmp.replace (reVal, "%26");
reVal = /#/g;
strTmp = strTmp.replace (reVal, "%23");
reVal = /\+/g;
strTmp = strTmp.replace (reVal, "%2b");
return (strTmp);
}

-------------------------------

function OrtHtmlLine (strVal)
{
var reVal;
var strTmp;
reVal = /\r/g;
strTmp = strVal.replace (reVal, "<br>");
return (strTmp);
}

-------------------------------

function OrtHtmlFormatLine (strVal)
{
return (OrtHtmlLine (OrtHtmlFormat (strVal)));
}

-------------------------------

function OrtHtmlSingleQuote (strVal)
{
var reVal;
var strTmp;
reVal = /'/g;
strTmp = strVal.replace (reVal, "\\'");
return (strTmp);
}

-------------------------------

function OrtHtmlDoubleQuote (strVal)
{
var reVal;
var strTmp;
reVal = /"/g;
strTmp = strVal.replace (reVal, '\\"');
return (strTmp);
}

-------------------------------

function OrtHtmlQuote (strVal)
{
return (OrtHtmlDoubleQuote (OrtHtmlSingleQuote (strVal)));
}

-------------------------------

function OrtGetGBStrLength (strVal)
{
var nLen;
var i;
nLen = 0;
for (i = 0; i < strVal.length; i ++)
{
if (strVal.charCodeAt (i) <= 255)
nLen ++;
else
nLen += 2;
}
return (nLen);
}

-------------------------------

function OrtCheckNumber (strVal)
{
var gar;
var tmp;
strVal = OrtTrimString (strVal);
if (strVal.length == "")
return (false);
reVal = /^[\-\+]?([0-9]\d*|0|[1-9]\d{0,2}(,\d{3})*)(\.\d+)?$/;
if (reVal.test (strVal))
{
gar = strVal + '.';
tmp = gar.split ('.');
if (tmp[0].length > 15)
return (false);
else
return (true);
}
return (false);
}

 


标签:有用 有用的 用的 判断 

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。本文出自“wpf之家”,请务必保留此出处:http://www.wpf123.com

上一篇:javascript页面跳转常用代码html教程
下一篇:没有了
相关评论
Copyright © 2009-2014 WPF之家(http://www.wpf123.com/) All rights reserved
 Powered by WPF之家
鄂ICP备13006396号