Cynthia,您需要将 id 添加到各种 HTML 元素,然后添加一些 javascript,如下所示:
$(function(){
function calcTFP(e) {
if(e) e.preventDefault();
var $tds, Pass_Yds, Pass_TDs, Int, Rush_Yds, Rush_TDs, Overall_Pts, TFP;
$("tbody#qb tr").each(function() {
$tds = $(this).find("td");
Pass_Yds = Number($tds.eq(2).text());
Pass_TDs = Number($tds.eq(3).text());
Int = Number($tds.eq(4).text());
Rush_Yds = Number($tds.eq(5).text());
Rush_TDs = Number($tds.eq(6).text());
TFP = Number($s_pass_yds_pts.val()) * Math.floor(Pass_Yds / Number($s_pass_yds_yds.val()));
TFP += Number($s_pass_tds_pts.val()) * Pass_TDs;
//TFP += ........; //for Rushing yds, based on Passing yds.
//TFP += ........; //for Rushing TDs, based on Passing TDs.
//TFP += ........; //for Ints Thrown, based on Passing TDs.
$tds.eq(8).text(TFP);//display calculated points in row's TFP column
});
}
//Passing Yds
var $s_pass_yds_pts = $("#s_pass_yds_pts").on('change', calcTFP);
var $s_pass_yds_yds = $("#s_pass_yds_yds").on('change', calcTFP);
//Passing TDs
var $s_pass_tds_pts = $("#s_pass_tds_pts").on('change', calcTFP);
//Rushing Yds
//add code here based on Passing Yds
//Rushing TDs
//add code here based on Passing TDs
//Int Thrown
//add code here based on Passing TDs
$("#b_get_TFP_scores").on('click', calcTFP);//attach calcTFP as click handler to "get_TFP_scores" button
calcTFP();//initial calculation on page load
})
演示在这里
您会看到代码只是部分完成了,但那里应该有足够的内容,包括注释,以便您弄清楚如何编写其余部分。一旦你对正在发生的事情有所了解,添加额外的代码将是非常机械的。
您还将看到 [Get TFP Scores] 按钮是多余的,因为计算是自动执行的 (a) 页面加载和 (b) 响应对选择菜单所做的更改。但是,我已将按钮留在原处。
编辑:
五分量计算分为两类:
- [通过Yds和Rashing Yds],一般公式为
pts = s1 * score / s2
。
- [传球、冲球和拦截],其中一般公式为
pts = s1 * score
。
上面我已经完成了两个示例计算(用于通过 Yds 和通过 TDs),即。每个类别中的一个。您需要根据适当的样本处理其他三个。
如果您还没有这样做,请记住还要添加(如在演示中):
<select>
您和<tbody>
元素的唯一 ID ,
- 元素的值属性
<option>
。