久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 php 和 javascript 時,在復選框名稱中使用括號

use brackets in checkbox name when using php and javascript?(使用 php 和 javascript 時,在復選框名稱中使用括號?)
本文介紹了使用 php 和 javascript 時,在復選框名稱中使用括號?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個帶有如下復選框的表單:

i have a form with checkboxes like this:

    <input type="checkbox" name="type[]" value="1" />Fast Food<br>
    <input type="checkbox" name="type[]" value="2" />Table Service<br>
    <input type="checkbox" name="type[]" value="3" />Cafeteria<br>

當我在名稱中使用方括號 (type[]) 時,我的 php 工作:

when i use the brackets in the name (type[]), my php works:

    $type=$_POST['type'];

    echo "types are:";
for ( $counter = 0; $counter < sizeof($type); $counter += 1) {
    echo "<br>".$type[$counter];
}

但我的 javascript 不起作用:

but my javascript doesn't work:

    var f = document.addform;
    for (var i=0;i<f.type.length;i++){
        if(f.type[i].checked==true){
            break;
        }
        if(i==(f.type.length-1)){
            alert("No categories entered!");
            valid=false;
        }
    }

但是,如果我去掉括號:

however, if i take away the brackets:

<input type="checkbox" name="type" value="1" />Fast Food<br>

然后 PHP 不起作用,但 javascript 起作用.

then the PHP doesn't work but the javascript does.

這是怎么回事?我應該用什么?

what's going on here? what should i use?

謝謝.

推薦答案

PHP 有一個不同尋常的系統來處理多個具有相同名稱的表單控件,它期望名稱包含 [] 但它沒有不要在變量名中使用它們.

PHP has an unusual system for handling multiple form controls with the same name, it expects the names to include [] but it doesn't use them in the variable name.

JavaScript 沒有這個問題.該屬性仍將包含括號.

JavaScript doesn't have that issue. The property will still have the brackets.

當然,方括號在JS中是有特殊意義的,所以不能用點號來訪問屬性.

Of course, square brackets have special meaning in JS, so you can't use dot notation to access the property.

f['type[]'][i].checked

這篇關于使用 php 和 javascript 時,在復選框名稱中使用括號?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 亚洲精品一区二区久 | 精品一区二区三区91 | 日韩高清国产一区在线 | 欧美一区二区三区在线视频 | 欧美精品一区在线 | 国产精品亚洲成在人线 | 嫩草视频在线免费观看 | 日韩综合在线 | 一区二区三区亚洲 | 久久免费看 | 欧美簧片 | 亚洲欧美日韩中文字幕一区二区三区 | 成人久久18免费 | 中文字幕第一页在线 | 久久精品久久精品久久精品 | 高清一区二区三区 | 99免费在线观看视频 | 亚洲免费视频在线观看 | 女女百合av大片一区二区三区九县 | 人人色视频 | 国产ts人妖系列高潮 | 日韩中文字幕在线视频 | 在线观看黄免费 | 色www精品视频在线观看 | 精品三级| 人人干人人舔 | 欧美日韩高清在线一区 | 范冰冰一级做a爰片久久毛片 | 日韩视频一区二区三区 | 能看的av网站 | 国产一区欧美 | 欧美一卡二卡在线观看 | 三级黄色大片网站 | www.成人在线视频 | 黄网站涩免费蜜桃网站 | 日韩欧美在线免费 | 亚洲精品一| 日韩在线不卡视频 | 91传媒在线观看 | 最新免费av网站 | 日韩在线精品视频 |