【问题标题】:redirect to next page if only check box is unchecked如果仅未选中复选框,则重定向到下一页
【发布时间】:2014-02-08 11:34:46
【问题描述】:

我有 html 表,当单击按钮时我有按钮重定向到下一页并显示与传递的数据有关的值,但我希望如果表中的任何复选框被选中,它不会重定向到下一页它只会重定向当表格中的所有复选框都未选中时,我尝试了但它不起作用,任何人都可以指导我。

ajax

    <script>

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

        var chkBox=document.getElementById("checkAddress").value;


        if (chkBox.checked == 0)
        {

     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=redirectclientpricenotification&clientid='+clientid+'';
                          $("#result").html(data);
                         $('.blockUI').hide();
        }
    }); 
        }

        else{

             alert("chkBox");

        }

    });
});

</script>

html

<th ><img  id='redirect'  src="/image/exporttt.png"  style="margin:-30 0 0 0px;cursor:pointer;"  >
</th>

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

【问题讨论】:

    标签: php html ajax checkbox


    【解决方案1】:
    $(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=redirectclientpricenotification&clientid='+clientid+'';
                              $("#result").html(data);
                             $('.blockUI').hide();
            }
        }); 
            }
    
            else{
    
                 alert("chkBox");
    
            }
    
        });
    });
    
    </script>
    

    【讨论】:

      【解决方案2】:

      进行以下更改:

      var chkBox=document.getElementById("checkAddress");
      

      不要附加 .value ,仅当您需要该值时才需要。如果其余代码没问题,这应该可以。

      【讨论】:

        【解决方案3】:

        试试这个,

        var chkBox=document.getElementById("checkAddress");
        console.log(chkBox.checked);
        

        【讨论】:

          【解决方案4】:

          用更少的变量试试这个:

          <script>
              $(document).ready(function () {
                  $("#redirect").click(function () {
                      if (document.getElementById("checkAddress").checked) {
                          $.blockUI({
                                  message: '<h2>Please wait...<img src="/image/loader.gif" /></h2>',
                                  timeout: 2000
                          });
                          $.ajax({
                              type: "post",
                              data: "clientid=" + document.getElementById("client").value,
                              success: function (data) {
                                  window.location = '?action=redirectclientpricenotification&clientid=' + document.getElementById("client").value + '';
                                  $("#result").html(data);
                                  $('.blockUI').hide();
                              }
                          });
                      } else {
          
                          alert("chkBox");
          
                      }
          
                  });
              });
          </script>
          

          【讨论】:

            猜你喜欢
            • 2014-02-12
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-03-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-08-19
            相关资源
            最近更新 更多