我需要显示使用ajax和php动态绑定的复选框。
我的代码是
<?php
include 'dbconnect.php';
$result = mysqli_query($link, "SELECT * FROM city where district_id='$dist' ");
while($city_row=mysqli_fetch_array($result)){
?>
<input type="checkbox" value="<?php echo $city_row['id']; ?>"/><?php echo $city_row['city_name']; ?>
<?php
}
}
?>
ajax脚本
$.ajax({
type: "POST",
cache: false,
url: "get_locality.php",
data:{districts:hi },
success: function(response){
alert(response);
$('#city').html(response);
}
});
html div
<div class="checkbox" ><span id="city">
</span>
</div>
但它只显示值。不显示复选框
答案 0 :(得分:-1)
问题是您只打印复选框的值而不是复选框html。因此,将所有代码存储在一个变量中并打印该变量。
def f(x):
return {
'+': (lambda x: x[1] + x[2]),
'-': (lambda x: x[1] - x[2])
}[x[0]](x)
print(f(["+",2,3])) # 5