JavaScript代碼在firefox下失效

yienzhu 2011-10-09 05:18:56
代碼在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>
...全文
100 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yienzhu 2011-10-09
  • 打赏
  • 举报
回复
已經搞定,謝謝。

[Quote=引用 2 楼 liangws 的回复:]

document.getElementById('date').innerText = p.options[p.selectedIndex].innerText.match(/\d+/);

在FF中。option节点没有innerText属性,得用innerHTML
[/Quote]
yienzhu 2011-10-09
  • 打赏
  • 举报
回复
已經搞定,謝謝。

[Quote=引用 1 楼 hookee 的回复:]

HTML code

<!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>
</……
[/Quote]
liangws 2011-10-09
  • 打赏
  • 举报
回复
document.getElementById('date').innerText = p.options[p.selectedIndex].innerText.match(/\d+/);

在FF中。option节点没有innerText属性,得用innerHTML
hookee 2011-10-09
  • 打赏
  • 举报
回复

<!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>

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧