2014-01-22 23 views
0

我有html表格,请参阅下面的html表格,如果用户单击标题中的图像,它将不会重定向它显示警报“请取消选中所有复选框”,它的唯一的重定向如果用户没有选中所有的复选框。我的问题是它现在重定向,因为第一个td未选中,它显示警报,如果第一个td检查,它只能采取第一个td我想采取所有td .can任何一个导是我的。见下面的代码如果所有复选框未选中,如何重定向到下一页

enter image description here

AJAX

<script> 

$(document).ready(function() { 
    $("#redirect").click(function() { 

     var chkBox=$("#checkAddress"); 

     if (chkBox.attr('checked') != 'checked') 
     { 

    var clientid=document.getElementById("client").value; 

     $.blockUI(

     { 

     message: '<h2>Please wait...</h2><img src="/image/loader.gif" />', 
    timeout: 2000 

     }); 


    $.ajax({ 
      type:"post", 

     data:"clientid="+clientid, 
     success:function(data){ 

         window.location = '?action=clientpricenotification&clientid='+clientid+''; 
          $("#result").html(data); 
         $('.blockUI').hide(); 
     } 
    }); 
     } 
     else 
     { 
      alert("Please uncheck all the td"); 
     } 
    }); 
}); 

</script> 

HTML

<th style="text-align:center ;width:200px">Route Update</th> 
    <th style="text-align:center ;width:90px">By(Emp)</th> 
    <th style="text-align:center ; width:32px"> <img id='redirect' src="/image/Picture12.png" style="margin:0px;cursor:pointer;"> </th> 

echo ' <td style="width:200px" id="CPH_GridView1_Status1'.$rows['id'].'" class="route status1 '.$rows["id"].' "><input type="checkbox" style="margin:0 0 0 93px;" id="checkAddress" '.$checked_value.' name="checkAddress" '.$checked_value.' ></td>  

<td id="CPH_GridView1_user" style="width:90px" class="edit user '.$rows["id"].'">'.$rows["user"].'</td>  

<td style="width:65px" class=" '.$rows["id"].'"></td>'; 

回答

1

这将听取所有复选框的change()事件,所以当它发现0检查,它会重定向。

var $checkbox = $("input[type=checkbox]"); 
var url = "http://....."; 
$checkbox.change(function(){ 
    if($checkbox.is(":checked").length == 0) { window.location=url; } 
}); 

它应该足以让您知道如何将它应用到您的代码。

+0

感谢我尝试了我你不能工作,你可以改变代码 – arok

0

使用document.getElementByTagname(“input”)..它将返回所有输入标签的列表,并且您必须遍历列表来检查每个checkbox.RIGHT现在您只是检查您的第一个复选框...

var allInputs = document.getElementsByTagName("input"); 
    for (var i = 0, max = allInputs.length; i < max; i++){ 
     if (allInputs[i].type === 'checkbox') 
      if (allInputs[i].attr('checked') != 'checked'){ 
        //your logic 
       } 
    } 
0

首先你应该确定所有输入的ID为:

id="checkAddress_{anythingunique}" 

然后

<script> 
    var redir=1; 
    $('input[id^="checkAddress_"]').each(function(){ 
     if(!$(this).attr('checked'))redire=0; 
    }); 
    if(redir==1){ 
     //do your action 
    } 
</script> 
相关问题