首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JS去掉空格有关问题

2012-03-04 
JS去掉空格问题原代码是:functiongetlengthB(str){returnstr.replace(/[ ^\x00-\xff\]/g, ).length}

JS去掉空格问题
原代码是:
function   getlengthB(str)
{   return   str.replace(/[ "   "^\x00-\xff\]/g, " ").length;
}
function   Checkdata()
{
document.getElementById( "titlestr ").innerHTML= " ";
document.getElementById( "constr ").innerHTML= " ";
             
ischeck=true
                CheckUbbUse( 'UserName ',1,document.getElementById( 'Body ').value)//定员帖检查
if   (getlengthB(document.Dvform.topic.value) <3   &&   ispostnew==1)
{
document.getElementById( "titlestr ").innerHTML= "   <font   color=\ "#FF0000\ "> ←您忘记填写标题 </font> "
document.Dvform.topic.focus();
ischeck=false
}
想在getlengthB函数中增加去掉空格的命令

[解决办法]
function getlengthB(str)
{
str = str.replace(/\s/g, " ");
return str.replace(/[ " "^\x00-\xff\]/g, " ").length;
}
[解决办法]

function getlengthB(str)
{
return str.replace(/[ " "^\x00-\xff\]/g, " ").length;
}

String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, " "); // 用正则表达式将前后空格
}

热点排行