<script>
function dele()

var is=0
var str=""
for(var i=1;i<document.f.cb.length;i++)
{
if(document.f.cb[i].checked)
{
is=1;
str+=document.f.cb[i].value + ","
}
}
if(is==0) alert("对不起,您没有选择要删除的项")
else
{
if(confirm("您确认要删除"+str+"项吗?"))

document.f.action="del.asp"
document.f.submit()
}
}
}
function modi()

var is=0
var str=""
for(var i=1;i<document.f.cb.length;i++)
{
if(document.f.cb[i].checked)
{
is+=1
alert(document.f.cb[i].value)
}
}
if(is!=1) alert("对不起"+is)
else
{
document.f.action="modi.asp"
document.f.submit()
}
}
function add()

document.f.action="add.asp"
document.f.submit()
}</script>
<form name="f">
<input name="cb" type="checkbox" value="A">
<input name="cb" type="checkbox" value="B">
<input name="cb" type="checkbox" value="C">
<input name="cb" type="checkbox" value="D">
<input name="del" value="Delete" type="button" onclick="dele()">
<input name="addnew" value="addnew" type="button" onclick="add()">
<input name="modify" value="modify" type="button" onclick="modi()">
</form>

解决方案 »

  1.   

    抱歉,刚才有点Bug<script>
    function dele()

    var is=0
    var str=""
    for(var i=0;i<document.f.cb.length;i++)
    {
    if(document.f.cb[i].checked)
    {
    is=1;
    str+=document.f.cb[i].value + ","
    }
    }
    if(is==0) alert("对不起,您没有选择要删除的项")
    else
    {
    if(confirm("您确认要删除"+str+"项吗?"))

    document.f.action="del.asp"
    document.f.submit()
    }
    }
    }
    function modi()

    var is=0
    var str=""
    for(var i=0;i<document.f.cb.length;i++)
    {
    if(document.f.cb[i].checked)
    {
    is+=1
    }
    }
    if(is==1)
    {
    document.f.action="modi.asp"
    document.f.submit()
    }
    else
    alert("对不起,多选或不选都会出现提示信息")
    }
    function add()

    document.f.action="add.asp"
    document.f.submit()
    }</script>
    <form name="f">
    <input name="cb" type="checkbox" value="A">
    <input name="cb" type="checkbox" value="B">
    <input name="cb" type="checkbox" value="C">
    <input name="cb" type="checkbox" value="D">
    <input name="del" value="Delete" type="button" onclick="dele()">
    <input name="addnew" value="addnew" type="button" onclick="add()">
    <input name="modify" value="modify" type="button" onclick="modi()">
    </form>
      

  2.   

    <script language=javascript>
    function add(){
    document.show.action="add.jsp";
    document.show.submit();
    }
    function sub(){
    var n=0;
    for(i=0;i<document.show.all("checkbox").length;i++)
    if(document.show.all("checkbox")[i].checked==true) n++;
    return n;
    }
    function modify(){
    if(sub()!=1) {
    alert("您一次只能修改一条记录!");
    return;
    }
    document.show.action="modify.jsp";
    document.show.submit();
    }function del(){
    if(sub()<1){
    alert("你没有选择要删除的记录");
    return;
    }
    if(!confirm("您确实要删除选定的"+sub()+"条记录吗?")) return;
    document.show.action="del.jsp";
    document.show.submit();
    }
    </script>
    <FORM NAME="show" ACTION="inq_cheque.jsp" METHOD="POST" >
      <p> 
        <input type="checkbox" name="checkbox" value="checkbox">
        324334 </p>
      <p> 
        <input type="checkbox" name="checkbox" value="checkbox">
        343434</p>
      <p> 
        <input type="checkbox" name="checkbox" value="checkbox">
        43434</p>
      <p> 
        <input type=button   value="新增" onclick=add()>
        <input type=button   value="修改" onclick=modify()>
        <input type=button   value="删除" onclick=del()>
      </p>
    </form>
      

  3.   

    试试这个:
    -------------
    <script language=javascript>
    function add(){
    document.show.action="add.jsp";
    document.show.submit();
    }
    function sub(){
    var n=0;
    if(document.show.all("checkbox")==null) return 0;//此时没有任何checkbox
    if(document.show.all("checkbox").length==null) {//此时可能有一个checkbox
    if(document.show.all("checkbox").checked==true) return 1;
    else return 0;
    } for(i=0;i<document.show.all("checkbox").length;i++)
    if(document.show.all("checkbox")[i].checked==true) n++;
    return n;
    }
    function modify(){
    if(sub()>1) {
    alert("您只能选择一条记录进行修改!");
    return;
    }else if(sub()<1){
    alert("您没有选择要修改的记录!");
    return;
    }
    document.show.action="modify.jsp";
    document.show.submit();
    }function del(){
    if(sub()<1){
    alert("你没有选择要删除的记录");
    return;
    }
    if(!confirm("您确实要删除选定的"+sub()+"条记录吗?")) return;
    document.show.action="del.jsp";
    document.show.submit();
    }
    </script>
    <FORM NAME="show" ACTION="inq_cheque.jsp" METHOD="POST" >
    <p> 
        <input type="checkbox" name="checkbox" value="checkbox">
        324334 </p>
      <p> 
        <input type="checkbox" name="checkbox" value="checkbox">
        343434</p>
      <p> 
        <input type="checkbox" name="checkbox" value="checkbox">
        43434</p>
      <p> 
        <input type=button   value="新增" onclick=add()>
        <input type=button   value="修改" onclick=modify()>
        <input type=button   value="删除" onclick=del()>
      </p>
    </form>