我只是新的使用Ajax和我正在從這個鏈接的教程http://ricochen.wordpress.com/2011/08/02/passing-array-of-checkbox-values-to-php-through-jquery-example/
但我無法使它的工作,你可以請幫助我嗎?Ajax和複選框陣列
的html代碼:
<html>
<head>
<script src="jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
function doit() {
var p=[];
$('input.cb').each(function() {
if($(this).attr('checked')) {
p.push($(this).attr('rel'));
}
});
$.ajax({
url:'/test2.php',
type:'POST',
data: {list:p},
success: function(res) {
alert(res);
}
});
}
</script>
</head>
<body>
<input type="checkbox" class="cb" rel="1"></input>This is 1<br />
<input type="checkbox" class="cb" rel="abc"></input>This is abc<br />
<input type="checkbox" class="cb" rel="999"></input>This is 999<br />
<a href="javascript:void(0)" onclick="doit()">Click</a>
</body>
</html>
test2.php:
<?php
print_r(@$_POST['list']);
?>
而正是不工作? – adeneo
嘗試只是功能DOIT(後提醒的東西){並檢查它是否正在提示.. – Jenz
@jenz我試圖用這個和更換的onClick功能和它的工作職能QWE() \t \t \t \t { \t \t \t \t alert('test'); \t \t \t \t} – zxc