<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<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;  
        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;  
    }  
  
</script>  
</head>  
<body>  
<select id="s">  
  <option  value='0'>  选项</option>  
</select>  
</body>  
</html>  
 posted on 2011-01-23 10:49  H&M  阅读(1263)  评论(0编辑  收藏  举报