本文目錄一覽:
php中的checkbox如何默認選中?看別人的回答看不懂
checkbox不是php哦,他是html中input的一個類型,在w3c當中有明確的input屬性值介紹:
checked checked 規定此 input 元素首次加載時應當被選中。
所以checkbox默認選中的操作是
input type=”checkbox” name=”checkbox” value=”” checked=”checked”
PHP中如何獲取多個checkbox的值
在PHP中獲取多個checkbox值可以用一下方法,一般在前端,我們的checkbox值都是通過POST請求到後端的,而POST值是一個數組,我們可以在前端命名checkbox節點的時候,用”[]”來添加到命名後面。
舉個例子,下面時前端代碼,注意name命名方式:
!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “
html xmlns=”
head
meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /
titledemo/title
/head
body
form id=”form1″ name=”form1″ method=”post” action=”a.php”
input name=”checkbox[]” type=”checkbox” id=”checkbox” value=”1″ /
input name=”checkbox[]” type=”checkbox” id=”checkbox” value=”2″ /
input name=”checkbox[]” type=”checkbox” id=”checkbox” value=”3″ /
input name=”checkbox[]” type=”checkbox” id=”checkbox” value=”4″ /
input type=”submit” name=”button” id=”button” value=”submit” /
/form
/body
/html
後端簡單點:
?php
print_r($_POST);
?
到最後我們看到的結果是這個:
Array
(
[checkbox] = Array
(
[0] = 1
[1] = 2
[2] = 3
[3] = 4
)
[button] = submit
)
從裡面可以看到checkbox中有多個值對應 1,2,3,4
這樣就可以多喝checkbox值傳遞了。
php怎麼獲取checkbox選中值
使用javascript獲取checkbox的value值,然後使用javascript的get請求發送給php頁面,後端php頁面就能獲取到這個value值了。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/219727.html