<script type="text/javascript">
function editcar() {
var carId="";
var checknum=0;
var s=document.getElementsByTagName("input");
for (var i=0;i<s.length;i++) {
if (s[i].getAttribute("name")=="checkbox")
if (s[i].checked){
checknum++;
carId+=s[i].value;
}
}
if (checknum!=1) {
alert("请选择一辆需要修改的车辆!");
return false;
}
location.href="<%=basePath%>car.do?method=editCar&carid="+carId;
}
function delsome() {
if(confirm("你确定要删除所选车辆信息吗?")){
var choice="";
var s=document.getElementsByTagName("input");
for (var i=0;i<s.length;i++) {
if (s[i].getAttribute("name")=="checkbox")
if (s[i].checked)
choice+=s[i].value+",";
}
if (choice)
location.href="<%=basePath%>car.do?method=delCar&carId="+choice;
else
alert("请选择需要删除的车辆!")
}
}
</script>
标签代码:
<input name="checkbox" type="checkbox" id="checkbox" value="${car.carId }">
删除部分的Action代码:
public ActionForward delCar(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String carId = request.getParameter("carId");
carService.delCar(carId);
return query(mapping,form,request,response);
}
service部分代码:
public void delCar(String carId) {
String arryId[] = carId.split(",");
for (int i = 0; i < arryId.length; i++) {
// SrcmCar car = new SrcmCar();
// car.setCarId(arryId[i]);
// this.getHibernateTemplate().delete(car);
String hql = "delete from SrcmCar where carId='" + arryId[i] + "'";
Query query = this.getSession().createQuery(hql);
query.executeUpdate();
}
}
posted on 2007-10-29 12:10
末日风情 阅读(3410)
评论(0) 编辑 收藏 所属分类:
javascript