这是我的代码
<select name="category_id">
<option value="0">All Categories</option>
<option value="57">Books</option>
<option value="63"> Aboriginal Authors & Studies</option>
<option value="64"> &nbsnbsp;Animals & Birds</option>
<option value="117"> Green Guide</option>
<option value="65"> Atlases</option>
<option value="86"> Regional Atlases</option>
<option value="87"> Road Atlases</option>
</select>
答案 0 :(得分:8)
如果不替换格式错误的
,您可以替换每个节点的innerHTML
var options = document.getElementsByTagName('option')
for (index = 0; index < options.length; ++index) {
options[index].innerHTML = options[index].innerHTML.replace(/\ /g, '');
}
答案 1 :(得分:2)
试试这个:
var str = "All Categories Books Aboriginal Authors & Studies &nbsnbsp;Animals & Birds Green Guide Atlases Regional Atlases Road Atlases";
var op = str.replace(/&nbsnbsp;/g, '');
alert(op);