allmob.js:
$(document).ready(function() {
$(':checkbox').change(function() {
var result1 = [];
$(':checkbox:checked').each(function() {
result1.push($(this).val());
});
var url = "mob1.php"
if (result1.length > 0) {
//var fin = result1 ;
$.post(url, { contval: result1 }, function(data) {
$('#result').html(data);
});
}
else {
$('#result').html("nothing is checked");
}
});
});
如果不是传递result1
而是传递1 $.post(url, { contval: 1 }, function(data)
,我会收到输出,如果我通过result1
,则会出现空白屏幕。
mob.php:
<?php
$contval = $_POST['contval'] ;
if ($contval == "1")
{
echo "1 is checked" ;
}
if($contval == "2")
{
echo "2 is selected" ;
}
?>
allmob.php
<?php
session_start();
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/allmob.css">
<script type = "text/javascript="js/jquery1.11.3.js"> </script>
<script type = "text/javascript" src ="js/allmob.js"></script>
</head>
<body>
<div class = "well">Add2Kart</div>
<div class = "container">
<div class = "row">
<div class = "col-lg-4">
<h5>Price :</h5>
<input type = "checkbox" name = "price" value = "1">₹1,000-₹5,000</input><br>
<input type = "checkbox" name = "price" value = "2">₹5,000-₹10,000</input><br>
<input type = "checkbox" name = "price" value = "3">₹10,000-₹15,000</input><br>
<input type = "checkbox" name = "price" value = "BETWEEN 15000 AND 25000">₹15,000-₹25,000</input><br>
</div>
<div class = "col-lg-8">
<div id = "result" >
</div>
</div>
</div>
</body>
</html>
选中的复选框由allmob.js处理,所选复选框的值发送到mob.php所以我想要做的是如果选择值1复选框然后在mob.php条件1打印如果机器人1和2复选框被选中两个条件都应打印
答案 0 :(得分:1)
试试这个......
$_POST['contval']
是一个数组,因此您无法使用“==
”直接检查它的值
<?php
$contval = $_POST['contval'] ;
if (!empty($contval) && in_array("1", $contval))
{
echo "1 is checked" ;
}
?>