古詩詞大全網 - 成語大全 - 在thinkphp中如何使用checkbox? 類似購物車的,如何用checkbox勾選n行數據,傳送到下壹個頁面顯示出來。

在thinkphp中如何使用checkbox? 類似購物車的,如何用checkbox勾選n行數據,傳送到下壹個頁面顯示出來。

$_POST表單提交後本來就會有勾選的checkbox值,如果要jQuery的話:

<html>

<head>

<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>

<title>GetCheckboxValues</title>

<script?language="javascript"?type="text/javascript"?src="../js/jquery-1.9.1.js"></script>

</head>

<body>

<input?type="checkbox"?name="ids[]"?value="abc"?/>

<input?type="checkbox"?name="ids[]"?value="def"?/>

<input?type="checkbox"?name="ids[]"?value="ghi"?/>

<input?id="btn"?type="button"?name="btn"?value="submit"?/>

<script>

jQuery(function(){

var?box?=?{

getBoxVal:function(){

array?=?new?Array();

$("input[name^='ids']").each(function(i){

if($(this).prop('checked')?==?true){

array?.push($(this).val());

}

});alert(array);

return?array;

},//end?getBoxVal

submitForm:function(){

arr?=?box.getBoxVal();

$("#btn").click(function(){

alert("arr:"+arr);

});

}//end?submitForm

}//end?box

box.submitForm();

});

</script>

</body>

</html>