当选中复选框时,我希望通过jquery将其值发送到其他PHP文件

时间:2021-12-11 13:41:36

Actually i want to send the value of checkbox when it is checked through jquery...means when i click on checkbox it has to send automatically...i tried with following code..

实际上,我想在通过jquery勾选时发送复选框的值……意思是当我点击复选框时,它必须自动发送…我尝试了以下代码。

$(document).ready(function () {
    $(".checkBox").change(function () {
        var s = $(this).val();
        var dataString = 's=' + s;
        $.ajax({
            type: "GET",
            url: "xyz.php",
            data: dataString,
            cache: false,
            success: function (html) {}
        });
    });
});

and html code is

和html代码是

<div class = "checkBox">
<input type = "checkbox" name = "select[]" value = <?php $friendUid?> />
</div>

I was unable to send to other page

我无法发送到其他页面

5 个解决方案

#1


3  

Change your html: Put the class = "checkBox" onto the checkbox element

更改html:将class = "checkBox"放在复选框元素上

<div>
<input type = "checkbox" name = "select[]" value = <?php $friendUid?>  class = "checkBox"/>
</div>

#2


1  

The selector $(".checkBox") will attach that function to any items with the class of checkBox, and since your checkbox does not have that as its class, you are actually attaching your function to the div that contains the checkbox instead, which of course will never trigger your function.

选择器$(“.checkBox”)将把该函数附加到带有复选框类的任何项上,而且由于您的复选框没有将其作为其类,所以您实际上是将函数附加到包含复选框的div中,当然这永远不会触发您的函数。

#3


0  

<?php $friendUid?> should be <?php echo $friendUid ?>

< ?php friendUid美元?>应该是< ?php echo $ friendUid ? >

#4


0  

with $(".checkbox") you're referencing something of class 'checkbox' (i.e., your div, not the actual checkbox). Add the class to the <input type='checkbox'> instead

使用$(".checkbox"),您引用了类'checkbox'(即。,您的div,而不是实际的复选框)。将类添加到

#5


0  

try this in your code and let us know what happens.

在代码中尝试一下,让我们知道发生了什么。

<script type="text/javascript">
   alert('check0');
   $(document).ready(function () {
      alert('check1');
      $(".checkBox").change(function () {
         alert('check2');
         var s = $(this).val();
         var dataString = 's=' + s;
         $.ajax({
            type: "GET",
            url: "test.php",
            data: dataString,
            cache: false,
            success: function (html) {
               alert('check3');
            }
         });
      });
   });
</script>

<input type="checkbox" class="checkBox" />

#1


3  

Change your html: Put the class = "checkBox" onto the checkbox element

更改html:将class = "checkBox"放在复选框元素上

<div>
<input type = "checkbox" name = "select[]" value = <?php $friendUid?>  class = "checkBox"/>
</div>

#2


1  

The selector $(".checkBox") will attach that function to any items with the class of checkBox, and since your checkbox does not have that as its class, you are actually attaching your function to the div that contains the checkbox instead, which of course will never trigger your function.

选择器$(“.checkBox”)将把该函数附加到带有复选框类的任何项上,而且由于您的复选框没有将其作为其类,所以您实际上是将函数附加到包含复选框的div中,当然这永远不会触发您的函数。

#3


0  

<?php $friendUid?> should be <?php echo $friendUid ?>

< ?php friendUid美元?>应该是< ?php echo $ friendUid ? >

#4


0  

with $(".checkbox") you're referencing something of class 'checkbox' (i.e., your div, not the actual checkbox). Add the class to the <input type='checkbox'> instead

使用$(".checkbox"),您引用了类'checkbox'(即。,您的div,而不是实际的复选框)。将类添加到

#5


0  

try this in your code and let us know what happens.

在代码中尝试一下,让我们知道发生了什么。

<script type="text/javascript">
   alert('check0');
   $(document).ready(function () {
      alert('check1');
      $(".checkBox").change(function () {
         alert('check2');
         var s = $(this).val();
         var dataString = 's=' + s;
         $.ajax({
            type: "GET",
            url: "test.php",
            data: dataString,
            cache: false,
            success: function (html) {
               alert('check3');
            }
         });
      });
   });
</script>

<input type="checkbox" class="checkBox" />