【发布时间】:2011-02-17 03:27:32
【问题描述】:
我在 html 中有这样的选择列表:
<input type="checkbox" name="drive_style" value=1 checked />123<br />
<input type="checkbox" name="drive_style" value=2 />123<br />
<input type="checkbox" name="drive_style" value=3 checked /> 123<br />
<input type="checkbox" name="drive_style" value=4 />123<br />
<input type="checkbox" name="drive_style" value=5 checked />123<br />
我必须像数组一样将 checked 框的 values(1, 3, ...) 发送到 php 脚本(我在 jquery 中使用 ajax) .类似于:drive_style[index]。
$.post('post_reply.php', {'drive_style' : $('drive_style')}, function(data){
alert(data);
});
在 PHP 脚本中:
print_r($_POST['drive_style']);
[对象对象]
更新: 我的新代码:
<input type="checkbox" name="drive_style[]" value=1 checked />123<br />
<input type="checkbox" name="drive_style[]" value=2 />123<br />
<input type="checkbox" name="drive_style[]" value=3 checked />123<br />
<input type="checkbox" name="drive_style[]" value=4 />123<br />
<input type="checkbox" name="drive_style[]" value=5 checked />123<br />
$.post('post_reply.php', {'drive_style':$('input[name=drive_style]').serialize()}, function(data){
alert(data);
});
它警告空字符串。
【问题讨论】:
-
我已经提到
input[name=drive_style]必须是input[name=drive_style[]]
标签: php html ajax select arrays