2011-01-27 87 views
0

如何在php脚本中使用ajax调用发布已选中复选框的值,即当用户单击复选框时,值将发布到php脚本。使用ajax发布复选框值

+0

先看看这篇文章,我想你可以适应你。 http://stackoverflow.com/questions/4816145/how-to-detect-that-a-user-has-unchecked-a-checkbox ---如果你只是需要在屏幕上打印其他东西,连接链接上面,将更改为<?回声'显示的东西'; ?> ..我认为会为你工作。 – B4NZ41 2011-01-27 12:35:05

+0

jQuery是一个选项吗? – 2011-01-27 12:36:27

回答

0

穿上复选框onclick事件:

​​3210

,并作出这样一个功能:

function postwithajax(e){ 
    //and here send with ajax e.checked 
} 
0

使用jQuery从HTML获取值

$("#submit").click(function(){ 
    var myarray = []; 
    $("#div input:checked").each(function() { 
     myarray.push($(this).val()); //push each val into the array 
     }); 
     // here post Array with ajax 
    }); 

的Html

<html> 
<head> 
</head> 
<body> 
<div id="div"> 
    <input type="checkbox" value="one_name" checked> 
<input type="checkbox" value="one_name1"> 
<input type="checkbox" value="one_name2"> 
<input type="button" value="submit" id="submit"> 
</div> 
<textarea id="t"></textarea> 
</body> 
</html>