![](/img/trans.png)
[英]I want the first checkbox to be autochecked when any of the other checkox are checked
[英]When a checkbox is checked i want to send its value to other PHP file through jquery
实际上我想通过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) {}
});
});
});
和HTML代码是
<div class = "checkBox">
<input type = "checkbox" name = "select[]" value = <?php $friendUid?> />
</div>
我无法发送到其他页面
更改你的html:把class = "checkBox"
放到checkbox元素上
<div>
<input type = "checkbox" name = "select[]" value = <?php $friendUid?> class = "checkBox"/>
</div>
选择器$(“。checkBox”)会将该函数附加到具有checkBox类的任何项目,并且由于您的复选框没有将其作为其类,因此您实际上将函数附加到包含复选框的div,当然永远不会触发你的功能。
<?php $friendUid?>
应该是<?php echo $friendUid ?>
使用$(“。checkbox”)你引用了一些类'复选框'(即你的div,而不是实际的复选框)。 将类添加到<input type='checkbox'>
在您的代码中尝试这一点,让我们知道会发生什么。
<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" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.