代碼在firefox下失效,有解決辦法嗎?先謝了~~~
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<head>
</head>
<html>
    <head>
        <title>test</title>
    </head>
    <body>
    <select name='us_p' id="us_p">
        <option value='10'>包月卡(30天)</option>
        <option value='30'>季度卡(90天)</option>
        <option value='60'>半年卡(180天)</option>
        <option value='100'>包年卡(365天)</option>
    </select>
    連接數
    <select name='goods_count' id="goods_count">
        <option value='1'>1</option>
        <option value='2'>2</option>
        <option value='3'>3</option>
        <option value='4'>4</option>
        <option value='5'>5</option>
        <option value='6'>6</option>
        <option value='7'>7</option>
        <option value='8'>8</option>
        <option value='9'>9</option>
        <option value='10'>10</option>
    </select>個
总价:<span id="total"></span>
<p>
您的使用时长将被延长<label id='date'></label>天,您可以同时使用<label id='count'></label>个设备连接。
    </body>
    <script language="JavaScript"> 
window.onload = function(){
    var p = document.getElementById('us_p');
    var c = document.getElementById('goods_count');
    var t = document.getElementById('total');
 //   t.innerHTML = Math.round(parseFloat(p.options[p.selectedIndex].value, 10) * parseFloat(c.options[c.selectedIndex].value, 10) * 100) /100;
    p.onchange = c.onchange = function(){
    //    不用再定义
    //    var p = document.getElementById('us_p');
    //    var c = document.getElementById('goods_count');
    //    var t = document.getElementById('total');
        t.innerHTML = Math.round(parseFloat(p.options[p.selectedIndex].value, 10) * parseFloat(c.options[c.selectedIndex].value, 10) * 100) /100;
    //要求没看清楚,这行改下吧
        document.getElementById('date').innerText = p.options[p.selectedIndex].innerText.match(/\d+/);
        document.getElementById('count').innerText = c.options[c.selectedIndex].value;
    }    //这样初始化更好点吧
    p.onchange();
    c.onchange();
}
</script>
</html>

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
    <head>
    </head>
    <html>
        <head>
            <title>test</title>
        </head>
        <body>
        <select name='us_p' id="us_p">
            <option value='10'>包月卡(30天)</option>
            <option value='30'>季度卡(90天)</option>
            <option value='60'>半年卡(180天)</option>
            <option value='100'>包年卡(365天)</option>
        </select>
        連接數
        <select name='goods_count' id="goods_count">
            <option value='1'>1</option>
            <option value='2'>2</option>
            <option value='3'>3</option>
            <option value='4'>4</option>
            <option value='5'>5</option>
            <option value='6'>6</option>
            <option value='7'>7</option>
            <option value='8'>8</option>
            <option value='9'>9</option>
            <option value='10'>10</option>
        </select>個
    总价:<span id="total"></span>
    <p>
    您的使用时长将被延长<label id='date'></label>天,您可以同时使用<label id='count'></label>个设备连接。
        </body>
        <script language="JavaScript"> 
    function doit(){
        var p = document.getElementById('us_p');
        var c = document.getElementById('goods_count');
        var t = document.getElementById('total');
        t.innerHTML = Math.round(parseFloat(p.options[p.selectedIndex].value, 10) * parseFloat(c.options[c.selectedIndex].value, 10) * 100) /100;
        document.getElementById('date').innerHTML = p.options[p.selectedIndex].innerHTML.match(/\d+/);
        document.getElementById('count').innerHTML = c.options[c.selectedIndex].value;
    }
    window.onload = function(){
        var p = document.getElementById('us_p');
        var c = document.getElementById('goods_count');
        p.onchange = c.onchange = doit;
        doit();
    }
    </script>
    </html>
      

  2.   

    document.getElementById('date').innerText = p.options[p.selectedIndex].innerText.match(/\d+/);在FF中。option节点没有innerText属性,得用innerHTML