<script type="text/javascript">
function deleteUser() {
var flag = false;
for (var i = 0; i < document.getElementsByName("checkbox2").length; i++) {
if (document.getElementsByName("checkbox2")[i].checked) {
flag = true;
}
}
if (!flag) {
alert("请选择需要删除的用户!");
return;
}
if (window.confirm("确认删除吗?")) {
with (document.getElementById("checkbox2")) {
method = "post";
action = "deleteAll.action";
submit();
}
}
} </script>
.
.
.
.
<!---->
<s:iterator value="#request.list" id="us">
<tr>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<input type="checkbox" name="checkbox2" id="checkbox2" />
</div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE6"><div align="center"><span class="STYLE19"><s:property value="#us.username"/></span></div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#us.type"/></div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#us.tel"/></div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center">192.168.0.124</div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#us.detail"/></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE21"><s:a href="deleteUser.action?user.id=%{#us.id}" onclick="return del();">删除</s:a> | 查看</div></td>
</tr>
</s:iterator>
//删除方法
public boolean deleteAllUsers(Integer id){
String hql = "from User user where id = "+id;
List<User> list = (List<User>)this.getHibernateTemplate().find(hql);
if(list!=null){
this.getHibernateTemplate().deleteAll(list);
return true;
}else {
return false;
}
} 想通过使用js来批量删除,但由于checkbox中的id号都一样,所以不可能执行,希望大家能帮帮忙,本人对js不是很了解(可以通过选中的id来批量删除对象,但我不知道怎么删除)
function deleteUser() {
var flag = false;
for (var i = 0; i < document.getElementsByName("checkbox2").length; i++) {
if (document.getElementsByName("checkbox2")[i].checked) {
flag = true;
}
}
if (!flag) {
alert("请选择需要删除的用户!");
return;
}
if (window.confirm("确认删除吗?")) {
with (document.getElementById("checkbox2")) {
method = "post";
action = "deleteAll.action";
submit();
}
}
} </script>
.
.
.
.
<!---->
<s:iterator value="#request.list" id="us">
<tr>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<input type="checkbox" name="checkbox2" id="checkbox2" />
</div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE6"><div align="center"><span class="STYLE19"><s:property value="#us.username"/></span></div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#us.type"/></div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#us.tel"/></div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center">192.168.0.124</div></td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#us.detail"/></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE21"><s:a href="deleteUser.action?user.id=%{#us.id}" onclick="return del();">删除</s:a> | 查看</div></td>
</tr>
</s:iterator>
//删除方法
public boolean deleteAllUsers(Integer id){
String hql = "from User user where id = "+id;
List<User> list = (List<User>)this.getHibernateTemplate().find(hql);
if(list!=null){
this.getHibernateTemplate().deleteAll(list);
return true;
}else {
return false;
}
} 想通过使用js来批量删除,但由于checkbox中的id号都一样,所以不可能执行,希望大家能帮帮忙,本人对js不是很了解(可以通过选中的id来批量删除对象,但我不知道怎么删除)
解决方案 »
- j2ee网站开发是先建表还是先写pojo
- 问问JSP提交后的问题
- 服务器是Apache Tomcat/4.0.6 现在出现了一个问题
- [开源]可高效率开发、高效率无限层级分布式部署的web 开发框架
- 求smartupload的下载地址及配置方法
- 表单值传递的问题,很奇怪
- 用swfupload 做的一个视频上传,遇到的蛋疼问题 求解
- resin3.06下如何配置oracle的数据库连接池,我找了好多资料,但是都没有配置成功
- 请问include一个页面的时候,怎样用变量来表示页面的链接啊?
- OutputStream output = response.getOutputStream();
- 求助html向JSP传输中文数据的乱码问题。
- 关于页面还原窗口,高手来。
var menus = "";
for(var i = 1 ;i < _chkGrp.length; i++){
if(_chkGrp[i].checked == true){
menus = menus + _chkGrp[i].value;
menus = menus + ",";
}
}
menus为你选中的所有的id,以“,”链接
把menus传给后台,用split(",")方法取得每一个id做删除操作
<input type="checkbox" name="usId" id="checkbox2" value="#us.id"/>
var arr=document.getElementsByName("usId");//这是一个数组,判断里面的是否选中(checked==true)了,把选中的id数组传到后台去,
否则,直接用表单提交就行了
if(aa.checked){
var ids=document.getElementById("ids").value;
document.getElementById("ids").value=ids+aa.value+",";
}else{
var ids=document.getElementById("ids").value;
document.getElementById("ids").value=ids.replace(aa.value+",","");
}
if(document.getElementById("ids").value!=""){
document.getElementById("tijiao").disabled=false;
}
}
<s:hidden name="ids" id="ids"/>
<s:iterator value="listBaseProcessFlowD" status="v" >
<tr>
<td>
<INPUT TYPE="checkbox" NAME="id" value="<s:property value="id"/>" onclick="check(this)"/>
</td>
</tr>
</s:iterator>
var chks=document.getElementsByName("checkbox2");
var ids=[];var count=0;
for(var i=0;i<chks.length;i++){
if(chks[i].checked){
ids.push(chks[i].value);
count+=1;
}
if(count==0){
alert("请选择记录");
}else if(confirm("您选中了【"+count+"】记录,确定删除?")){
var url="deleteAll.action?ids="+ids;
window.location=url;
}
}
注意你要在action类里加入 int[] checkid ;set get 方法<script type="text/javascript">
function remove(){
var checkid = name('checkid');
if (checkedCount(checkid) == 0) {
alert('请选择要删除的数据!');
return;
}
if(!window.confirm('你确定要删除吗?')){
return;
}
document.forms[0].action = "commentRemove.do";
document.forms[0].submit();
}
</script><s:form action="commentList.do" method="post" theme="simple" validate="false">
<li><input type="button" value="删除" onclick="javascript:remove();" /></li> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="table-layout:fixed;" >
<tr>
<td width="5%" align="center" valign="top"><span><input name="checkallname" id="checkallid" type="checkbox" onclick="javascript:checkAllBox();"></span></td>
<td align="center" width="15%"><span>资源标题</span></td>
<td align="center" width="10%"><span>操作</span></td>
</tr>
<s:iterator id="list" value="feedbackList.list">
<tr>
<td><input name="checkid" id="checkid" type="checkbox" value="<s:property value='#list.feedId'/>" /></td>
<td><s:property value='#list.gatherRes.passname' /> </td>
<td><a href="javascript:if(window.confirm('你确定要删除吗?')){window.location='commentRemove.do?checkid=<s:property value='#list.feedId'/>';}">删除</a> </td>
</tr>
</s:iterator>
</table>
</s:form>