JSfunction delete(name){var ok=confirm("Delete contact"+name);
if(ok==false)
return false;
else
return true;
}function checkAll(){
  for(var i=0;i<document.all.id.length;i++){
  document.all.id[i].checked=true; 
  }
}
//////////////////////////////////////////
<table border="1" bordercolordark="#000000" bordercolorlight="#000000" width="90%" height="600">
<tr>
<td align="center" width="12%">PB HOME</td>
<td align="center" >
<table border="1" bordercolordark="#000000" bordercolorlight="#000000" width="95%">
<tr bgcolor="#cccccc">
<th width="48" height="38" >Check Box</th>
<th width="105" >Name</th>
<th width="119">Mobile</th>
<th width="110">Home</th>
<th width="119">Office</th>
<th width="128" >Action</th>
</tr>
<#list list as contact>
<tr>
<td><input type="checkbox" name="id" value="${contact.id}"></td>
<td><input type="hidden" name="name" value="${contact.name}">${contact.name}</td>
<td>${contact.mobile}</td>
<td>${contact.home}</td>
<td>${contact.office}</td>
<td>
<table border="1" bordercolordark="#000000" bordercolorlight="#000000" width=100%>
<tr>
<td><a href="/MiniContact/detail?id=${contact.id}">Detail</a></td>
<td><a href="/MiniContact/detail?idd=${contact.id}" >Edit</a></td>
<td><a onClick="delete(${contact.name})" href="/MiniContact/delete?id=${contact.id}">Delete</a></td>//在此为何不执行JS方法 而直接跳转</tr>
</table>
</td>
</tr>
</#list>
<td height="64">
<tr>
<td height="59" colspan="6" align="center">
<table border="1" cellspacing="0" width="100%">
<tr>
<td><a href="ShowAllContact.ftl" onClick="checkAll()">Check All</a></td>//在此也不执行JS方法!
<td><input type="button"  onClick="deleteAll()" value="Delete Checked"></td>
<td><a href="/MiniContact/addContact.ftl">Add Contact</a></td>
</tr>
    </table>

解决方案 »

  1.   

    整个jsp文件贴出来看下?
      

  2.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <style type="text/css">
    td{text-align:center;}
    th{text-align:center;}
    </style><script type="text/javascript">
    function deleteAll(){
    var allValue="";
    var count=0;
    for(var i=0;i<document.all.id.length;i++){

    if(document.all.id[i].checked==true)
    allValue+=document.all.id[i].value+",";

    while(count==document.all.id.length){
    var confirm=confirm("Are you sure to delete all Contacts?");
    if(confirm=="true")
    window.open("/MiniContact/delete?id=all");
    break;
    }
    count++;
    }
    var confirm=confirm("Are you sure to delete these Contacts?");
    if(comfirm=="true")
    window.open("/MiniContact/delete?id="+allValue);
    }function delete(name){var ok=confirm("Delete contact"+name);
    if(ok==false)
    return false;
    else
    return true;
    }
    function checkAll(){
      for(var i=0;i<document.all.id.length;i++){
      document.all.id[i].checked=true; 
      }
    }
    </script><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Show All Contact</title>
    </head>
    <body>
    <center>
    <br>
    <br>
    <br>
    <h2>OPERATOR SPECIFIC CUSTOMIZATION</h2>
    <hr noshade>
    <form>
    <table border="1" bordercolordark="#000000" bordercolorlight="#000000" width="90%" height="600">
    <tr>
    <td align="center" width="12%">PB HOME</td>
    <td align="center" >
    <table border="1" bordercolordark="#000000" bordercolorlight="#000000" width="95%">
    <tr bgcolor="#cccccc">
    <th width="48" height="38" >Check Box</th>
    <th width="105" >Name</th>
    <th width="119">Mobile</th>
    <th width="110">Home</th>
    <th width="119">Office</th>
    <th width="128" >Action</th>
    </tr>
    <#list list as contact>
    <tr>
    <td><input type="checkbox" name="id" value="${contact.id}"></td>
    <td><input type="hidden" name="name" value="${contact.name}">${contact.name}</td>
    <td>${contact.mobile}</td>
    <td>${contact.home}</td>
    <td>${contact.office}</td>
    <td>
    <table border="1" bordercolordark="#000000" bordercolorlight="#000000" width=100%>
    <tr>
    <td><a href="/MiniContact/detail?id=${contact.id}">Detail</a></td>
    <td><a href="/MiniContact/detail?idd=${contact.id}" >Edit</a></td>
    <td><a onClick="delete(${contact.name})" href="/MiniContact/delete?id=${contact.id}" >Delete</a></td>
    </tr>
    </table>
    </td>
    </tr>
    </#list>
    <td height="64">
    <tr>
    <td height="59" colspan="6" align="center">
    <table border="1" cellspacing="0" width="100%">
    <tr>
    <td><a href="ShowAllContact.ftl" onClick="checkAll()">Check All</a></td>
    <td><input type="button"  onClick="deleteAll()" value="Delete Checked"></td>
    <td><a href="/MiniContact/addContact.ftl">Add Contact</a></td>
    </tr>
        </table>
    </tr>
    <tr>
    <td align="center" colspan="6"><a href="/MiniContact/search.ftl">Search</a></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>
    </center>
    </body>
    </html>
    我的FreeMarker 不是JSP
    不过和这个没多少关系!
    希望大家多帮忙 我的JS很差
      

  3.   

    onClick="alert('hello')"
    扔进去看看执行么<td> <a   href="ShowAllContact.ftl"   onClick="checkAll()"> Check   All </a> </td> 
    <td> <input   type="button"     onClick="deleteAll()"   value="Delete   Checked"> </td> 
    难道deleteAll()执行的checkAll()就不执行?
    太诡异了巴
      

  4.   

    一般JS没有执行,可能是你的JS有错误,用Firebug调试一下看有没有错误
      

  5.   

    忘说了
    都不执行  我只是着重的突出checkAll() 呵呵
    代码有问题吗?还有
    td> <a   onClick="delete(${contact.name})"   href="/MiniContact/delete?id=${contact.id}"> Delete </a> </td>
    这句为什么不执行JS呢?放了 alert();没反应!
      

  6.   

    貌似所有的onClick后面都少了个';' 符号。
    如 onClick="deleteAll()" 应该为 onClick="deleteAll();" 。不知道说的对不对,呵呵。见谅!      
      

  7.   

    ;在JS中没关系的,我认为还是你的JS代码中有错误,你与其等着还不如自己用Firefox调试一下,如果你的代码中没有错误的话,
    <a onClick="delete(${contact.name})" href="/MiniContact/delete?id=${contact.id}">Delete</a>这个会执行的。
    顺便说一下,为什么你发代码不用CSDN的代码高亮呢?这样的代码贴出来看都懒的看了,一点格式都没有
      

  8.   

    !DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <style   type="text/css"> 
    td{text-align:center;} 
    th{text-align:center;} 
    </style> <script   type="text/javascript"> 
    function   deleteAll(){ 
    var   allValue=""; 
    var   count=0; 
    for(var   i=0;i <document.all.id.length;i++){ if(document.all.id[i].checked==true) 
    allValue+=document.all.id[i].value+","; while(count==document.all.id.length){ 
    var   confirm=confirm("Are   you   sure   to   delete   all   Contacts?"); 
    if(confirm=="true") 
    window.open("/MiniContact/delete?id=all"); 
    break; 

    count++; 

    var   confirm=confirm("Are   you   sure   to   delete   these   Contacts?"); 
    if(comfirm=="true") 
    window.open("/MiniContact/delete?id="+allValue); 

    function   delete(name){ var   ok=confirm("Delete   contact"+name); 
    if(ok==false) 
    return   false; 
    else 
    return   true; 

    function   checkAll(){ 
        for(var   i=0;i <document.all.id.length;i++){ 
        document.all.id[i].checked=true;   
        } 

    </script> <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312"> 
    <title> Show   All   Contact </title> 
    </head> 
    <body> 
    <center> 
    <br> 
    <br> 
    <br> 
    <h2> OPERATOR   SPECIFIC   CUSTOMIZATION </h2> 
    <hr   noshade> 
    <form> 
    <table   border="1"   bordercolordark="#000000"   bordercolorlight="#000000"   width="90%"   height="600"> 
    <tr> 
    <td   align="center"   width="12%"> PB   HOME </td> 
    <td   align="center"   > 
    <table   border="1"   bordercolordark="#000000"   bordercolorlight="#000000"   width="95%"> 
    <tr   bgcolor="#cccccc"> 
    <th   width="48"   height="38"   > Check   Box </th> 
    <th   width="105"   > Name </th> 
    <th   width="119"> Mobile </th> 
    <th   width="110"> Home </th> 
    <th   width="119"> Office </th> 
    <th   width="128"   > Action </th> 
    </tr> 
    <#list   list   as   contact> 
    <tr> 
    <td> <input   type="checkbox"   name="id"   value="${contact.id}"> </td> 
    <td> <input   type="hidden"   name="name"   value="${contact.name}"> ${contact.name} </td> 
    <td> ${contact.mobile} </td> 
    <td> ${contact.home} </td> 
    <td> ${contact.office} </td> 
    <td> 
    <table   border="1"   bordercolordark="#000000"   bordercolorlight="#000000"   width=100%> 
    <tr> 
    <td> <a   href="/MiniContact/detail?id=${contact.id}"> Detail </a> </td> 
    <td> <a   href="/MiniContact/detail?idd=${contact.id}"   > Edit </a> </td> 
    <td> <a   onClick="delete(${contact.name})"   href="/MiniContact/delete?id=${contact.id}"   > Delete </a> </td> 
    </tr> 
    </table> 
    </td> 
    </tr> 
    </#list> 
    <td   height="64"> 
    <tr> 
    <td   height="59"   colspan="6"   align="center"> 
    <table   border="1"   cellspacing="0"   width="100%"> 
    <tr> 
    <td> <a   href="ShowAllContact.ftl"   onClick="checkAll()"> Check   All </a> </td> 
    <td> <input   type="button"     onClick="deleteAll()"   value="Delete   Checked"> </td> 
    <td> <a   href="/MiniContact/addContact.ftl"> Add   Contact </a> </td> 
    </tr> 
            </table> 
    </tr> 
    <tr> 
    <td   align="center"   colspan="6"> <a   href="/MiniContact/search.ftl"> Search </a> </td> 
    </tr> 
    </table> 
    </td> 
    </tr> 
    </table> 
    </form> 
    </center> 
    </body> 
    </html>
      

  9.   

    delete是内置函数,换个名字,再推荐你用firefox调一下,很快就可以找到原因,不用浪费这么多时间
      

  10.   

    呵呵,问题解决了就好,积累经验了,我以前也不知道delete()是内置函数的
      

  11.   

    呵呵  原来我用了一些内置的函数

    delete(), confirm关键字 etc
    谢谢大家