如何用javascript控制点击超链接 本帖最后由 index_jsf 于 2011-11-20 19:41:31 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var obj = docement.fom.elements; 这个写的什么语法 html元素的id不能重复,否则只有一个生效。 var obj = document.form.elements;应该是这样吧? 我写的 fom 就是form的id var allCK=document.getElementsByName('delid'),checkedIDs=[],i=0;while(allCK[i++].checked) checkedIDs.push(allCK[i-1].value);var a=document.getElementById('delete');a.setAttribute("href","GoodsDelete.action?goodNum="+checkedIDs.join(','));a.click(); 在复选框的 onchange 事件中,调用 JS 函数,判断是否选中,如选中,则去掉链接.<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>查看|</title><script type="text/javascript">function ck(i){ if(i==1){ document.getElementById("myurl").innerHTML="" }}</script></head><body><div id="myurl"><a href="GoodsSelect.action?goodNum=${list.goodNum}">查看|</a></div><input type="checkbox" id="delck" value="0" onclick="ck(this.checked);"></body></html> 呃、、、好吧 我写的name,id 全是fom jsp?你有form么?你看一看解析完的HTML源码? 我是新手,麻烦写点注释,对javascript不熟悉,谢谢 在foreach中ID会重复.document.getElementByID也不能工作!用class或扩展属性(像rel)用document.getElementsByTagName找input如果有指定的属性再判断.like thisfunction highlightRows(){ if(!document.getElementsByTagName) return false; var tables=document.getElementsByTagName("table"); for(var i=0;i<tables.length;i++){ if(tables[i].getAttribute("rel")){ var rows=tables[i].getElementsByTagName("tr"); for(var j=0;j<rows.length;j++){ var oldClassName=rows[j].className; rows[j].onmouseover=function(){this.className="currentrow";} rows[j].onmouseout=function(){this.className=(oldClassName=="")?"normalrow":oldClassName;} } }else{continue;} }} ///////////////////////////////////////////////////////----js方法function deleteAll(){ var checkeds = document.fom.elements; for(var i=1;i<=checkeds.length;i++){ if(checkeds[i].checked==true) { var b=document.getElementById("chuanzhi"+i/2).value; var a=document.getElementById('delete'+i/2); a.setAttribute("href","GoodsDelete.action?goodNum="+b); a.click(); } }}//////////////////////////////////////////////////////////////js结束/////////////////////////////////////////////////////////////列表部分代码<% int q =1; %> <c:forEach items="${gvList}" var="list" > <tr bgcolor="#FFFFFF"> <td height="20"><input type="checkbox" id = "ck" name="delid<%=q%>"/></td> <td>${list.goodNum}</td> <td>${list.goodName}</td> <td>${list.goodNums}</td> <td>${list.good1}</td> <td> <a href="GoodsToUpdate.action?goodNum=${list.goodNum}">编辑|</a> <a href="GoodsSelect.action?goodNum=${list.goodNum}">查看|</a> <input type="hidden" id="chuanzhi<%=q%>" value="${list.goodNum}"/> <a id="delete<%=q%>" href="GoodsDelete.action?goodNum=${list.goodNum}">删除</a> </td> </tr> <%q++;%> </c:forEach>///////////////////////////////////////////////////////////////结束实现一键删除功能调试完毕 贴上代码。。谢谢各位的帮助 如何为动态增加的input数组相应的赋值 各位高手求解决方案? jquery+ajax加载xml的问题 document.write("<script……")与document.write("<scri"+"pt……")的区别 如何获取使用样式定义的DIV高度 请问这段代码错在哪里了? 点击表单提交文件,如何出现“文件上传中,请稍等”的文字? 很是困惑,关于table里对象的引用~~~ 关于文件上传对象只读问题 已经导入js文件了,但是其功能无法实现 document.when的值获取不到!! 改变文本域的字体属性
while(allCK[i++].checked)
checkedIDs.push(allCK[i-1].value);var a=document.getElementById('delete');
a.setAttribute("href","GoodsDelete.action?goodNum="+checkedIDs.join(','));
a.click();
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>查看|</title>
<script type="text/javascript">
function ck(i){
if(i==1){
document.getElementById("myurl").innerHTML=""
}
}
</script>
</head><body>
<div id="myurl">
<a href="GoodsSelect.action?goodNum=${list.goodNum}">查看|</a>
</div>
<input type="checkbox" id="delck" value="0" onclick="ck(this.checked);">
</body></html>
if(!document.getElementsByTagName) return false;
var tables=document.getElementsByTagName("table");
for(var i=0;i<tables.length;i++){
if(tables[i].getAttribute("rel")){
var rows=tables[i].getElementsByTagName("tr");
for(var j=0;j<rows.length;j++){
var oldClassName=rows[j].className;
rows[j].onmouseover=function(){this.className="currentrow";}
rows[j].onmouseout=function(){this.className=(oldClassName=="")?"normalrow":oldClassName;}
}
}else{continue;}
}
}
function deleteAll(){
var checkeds = document.fom.elements;
for(var i=1;i<=checkeds.length;i++){
if(checkeds[i].checked==true)
{
var b=document.getElementById("chuanzhi"+i/2).value;
var a=document.getElementById('delete'+i/2);
a.setAttribute("href","GoodsDelete.action?goodNum="+b);
a.click();
}
}
}
//////////////////////////////////////////////////////////////js结束/////////////////////////////////////////////////////////////列表部分代码
<%
int q =1;
%>
<c:forEach items="${gvList}" var="list" >
<tr bgcolor="#FFFFFF">
<td height="20"><input type="checkbox" id = "ck" name="delid<%=q%>"/></td>
<td>${list.goodNum}</td>
<td>${list.goodName}</td>
<td>${list.goodNums}</td>
<td>${list.good1}</td>
<td>
<a href="GoodsToUpdate.action?goodNum=${list.goodNum}">编辑|</a>
<a href="GoodsSelect.action?goodNum=${list.goodNum}">查看|</a>
<input type="hidden" id="chuanzhi<%=q%>" value="${list.goodNum}"/>
<a id="delete<%=q%>" href="GoodsDelete.action?goodNum=${list.goodNum}">删除</a>
</td>
</tr>
<%q++;%>
</c:forEach>
///////////////////////////////////////////////////////////////结束
实现一键删除功能
调试完毕 贴上代码。。谢谢各位的帮助