js打分
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>js打分</title>
<script type="text/javascript">
function grade(){
//获取鼠标点击左边的像素
var len=window.event.x-document.getElementById('bg').offsetLeft;
//设置鼠标点击左边的颜色
document.getElementById('bg').innerHTML="<div style='width:"+len+"px;background:blue;'></div>"
//计算分数
var val=((len/500)*100).toFixed(0);
document.getElementById('score').innerHTML=val+"";
}
</script>
</head>
<body>
<div id="bg" style="width:500px;background:red;" onclick="grade();" ></div>
<span id="score"></span>
</body>
</html>