我的php文件中有一个选择列表:
<select onchange="storePolishType(this.value,this.options[this.selectedIndex].text);" class="drop_down1">
<option value="10">BRP</option>
<option value="10">Polished Ends</option>
<option selected="selected" value="11">Sawed Ends</option>
<option value="10">Steeled Ends</option>
</select>
我在java脚本文件中有一个storePolishType
函数。在该函数中,我试图删除字符串之前和之后的空格:
function storePolishType(pTypeID,bottom_polish_name)
{
if(typeof bottom_polish_name != 'undefined')
{
bottom_polish_name = bottom_polish_name.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
}
它在Firefox中工作正常,但在IE8中无效。我也尝试了jquery的$.trim()
函数,它在IE8中也不起作用。
请帮我解决这个问题。
答案 0 :(得分:-1)
试试这个:
function trim(s){
if(typeof(s) === 'undefined'){return;}
return s.replace(/^\s+|\s+$/g,"");
}
如果你想使用你的功能,你可以输入“”而不是\ s并尝试它。