今天用jquery选择器动态的定位按钮,出现了只能定位到一组按钮的第一个,问题闹了好半天,终于解决了.
先上代码:
<#list returnMap.centers as centerList>
<#if (centerList_index < 10)>
<tr>
<td>${centerList_index+1}</td>
<td>${centerList.handle!}</td>
<td>${centerList.date?string("yyyy-MM-dd")!}</td>
<td>${centerList.fromhospital!}</td>
<td>${centerList.department!}</td>
<td>${centerList.tohospital!}</td>
<td>${centerList.todepartment!}</td>
<td>${centerList.validtime!}天</td>
<td>
<#if centerList.pstatus=="0">
<input type="button" disabled="true" id="${centerList.id}" name="chakan" value="查看" οnclick="catchcase('${centerList.id}','${centerList.handle}','${centerList.fromhospital}','${centerList.department}');"/>
<input type="button" disabled="true" id="${centerList.id}" name="quxiao" value="已取消" οnclick="del('${centerList.id}','${centerList.handle}');"/>
<#else>
<input type="button" id="${centerList.id}" name="chakan" value="查看" οnclick="catchcase('${centerList.id}','${centerList.handle}','${centerList.fromhospital}','${centerList.department}');"/>
<input type="button" id="${centerList.id}" name="quxiao" value="取消" οnclick="del('${centerList.id}','${centerList.handle}');"/>
</#if>
</td>
</tr>
</#if>
</#list>
</table>
<#else>
未查到结果
</#if>
</div>
<div style="clear: both;"></div>
</div>
</div>
<script type="text/javascript">
// 点击查看按钮
function catchcase(cid,handle,hospital,department) {
location.href = "${request.contextPath}/caseListTr.action?cid="+cid+"&handle="+handle+"&fromhospital="+hospital+"&department="+department+"&page=1";
};
// 点击取消按钮
function del(cid,handle) {
$.ajax({
url:"${request.contextPath}/centerDelete.action?cid="+cid+"&handle="+handle,
type:"post",
success:function(data){
var json = eval("("+data+")");
if(json.success){
$("#"+cid+"[name='chakan']").attr("disabled",true);
$("#"+cid+"[name='quxiao']").attr("disabled",true);
$("#"+cid+"[name='quxiao']").val("已取消");
}
}
});
};
</script>
这样的,每组按钮只能定位到第一个按钮,后来查资料发现,id是唯一的,不能相同,所以把id换成了class就可以了,要记住教训!!!!!