我的 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 中也不起作用。
请帮我解决这个问题。
最佳答案
试试这个:
function trim(s){
if(typeof(s) === 'undefined'){return;}
return s.replace(/^\s+|\s+$/g,"");
}
如果你想使用你的函数,你可以键入 ""而不是\s 并尝试它。
关于Javascript 删除空格在 IE8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5907384/