Option中的空格测试,Firefox与IE不同,求解

<option value="0">  选项,用str.match(/\s/g)来测试,IE取不到空格,但Firefox取到2个。求两者的兼容。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Option中的空格测试</title>
<script language="javascript">
window.onload = function(){
var str = document.getElementById("s").options[0].text;
var r = str.match(/\s/g)?str.match(/\s/g).length:0;
alert("Option中的空格数为:" + r);
}
</script>
</head>
<body>
<select id="s">
<option value="0">  选项</option>
</select>
</body>
</html>

问题补充:
我觉得两者都为2合适些</option>

[code="java"]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



Option中的空格测试 window.onload = function(){ var str = document.getElementById("s").options[0].text; str = htmlDecode(str); var r = str.match(/\s/g)?str.match(/\s/g).length:0; alert("Option中的空格数为:" + r); } function htmlEncode (str){ var div = document.createElement("div"); var text = document.createTextNode(str); div.appendChild(text); return div.innerHTML; } function htmlDecode (str){ var div = document.createElement("div"); div.innerHTML = str; return document.all?div.innerText:div.textContent; }




  选项


[/code],试试!

求两者的兼容.
你是想0两是想要2?