<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>
[code="java"]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
[/code],试试!
求两者的兼容.
你是想0两是想要2?