我想为复选框应用if-else语句

时间:2016-04-17 18:20:36

标签: javascript

我正在制作考勤系统,用户需要选中复选框,并且有"Present""Absent"两个复选框,因此如果存在复选框,则单击它应该打印出现在excel文件上我在JavaScript的循环帮助中包含了这些内容。

这是我的JavaScript代码:

function fillHidTable(){
    var htqf; //-- hidden field
    var rf; //-- retrieved field
    for ( var i = 1; i < 121; i++ ) {
        rf = "htqf"+i;
        document.getElementById(rf).innerHTML = document.getElementById("Q"+i+"CALC").value;
    }
    tableToExcel('hidTable', 'Analysis Results');
}

var tableToExcel = (function() {
    var uri = 'data:application/vnd.ms-excel;base64,'
            , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
            , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
            , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
    return function(table, name) {
        if (!table.nodeType) table = document.getElementById(table)
        var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
        window.location.href = uri + base64(format(template, ctx))
    }
})()

这是我的HTML代码:

 <tr>
    <td class="allbdrCenTop">1</td>
    <td class="allbdrLtTop">Third Year</td>
    <td class="allbdrLtTop"> Aarsi Mudgal</td>
    <td class="allbdrCenMid">
        <h></h><input id="Q1CALC" type="checkbox" value="P" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q1CALC"/>
    </td>
     <td class="allbdrCenMid">
        <h></h><input id="Q2CALC" type="checkbox" value="A" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q2CALC"/>
    </td>

</tr>

<tr>
    <td class="allbdrCenTop">2</td>
    <td class="allbdrLtTop">Third Year</td>
    <td class="allbdrLtTop">Aarti Sharma</td>
    <td class="allbdrCenMid">
        <input id="Q3CALC" type="checkbox" value="P" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q3CALC"/>
    </td>
     <td class="allbdrCenMid">
        <input id="Q4CALC" type="checkbox" value="A" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q4CALC"/>
    </td>
</tr>
<tr>
    <td class="allbdrCenTop">3</td>
    <td class="allbdrLtTop">Third Year</td>
    <td class="allbdrLtTop">Aarzoo Khan</td>
    <td class="allbdrCenMid">
        <input id="Q5CALC" type="checkbox" value="P" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q5CALC"/>
    </td>
     <td class="allbdrCenMid">
        <input id="Q6CALC" type="checkbox" value="A" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q6CALC"/>
    </td>
</tr>

0 个答案:

没有答案