1. 給複選框添加onclick事件 獲取標籤idthis
1 <tbody> 2 <c:forEach var="file" items="${files}"> 3 <tr class="er" onMouseMove="changeTrColor(this)"> 4 <td class="xuanze"><input type="checkbox" name="r" value="${file.id}" onclick="aa()"/></td> 5 <td class="name">${file.filename}</td> 6 <td class="daxiao">15k</td> 7 <td class="time"><a href="#">2015-01-01</a> <select><option>刪除</option><option>移動到</option><option>複製到</option><option>下載</option></select></td> 8 </tr> 9 </c:forEach> 10 </tbody>
2。給a標籤添加idspa
1 <div class="btn2"> 2 <a href="#" id="xiazai">下載</a> 3 <a href="#">刪除</a> 4 <a href="#">打印</a> 5 </div>
3.獲取複選框id修改href屬性code
1 function aa(){ 2 alert("aa"); 3 var r=document.getElementsByName("r"); 4 for(var i=0;i<r.length;i++){ 5 if(r[i].checked){ 6 alert(r[i].value); 7 var num = r[i].value; 8 document.getElementById("xiazai").href="file/download?id="+num; 9 } 10 } 11 }