久久久久久久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)
主站蜘蛛池模板: 国产精品高潮呻吟久久av黑人 | 亚洲大片在线观看 | 欧美日韩成人在线 | 亚洲精品中文在线 | 欧美色综合一区二区三区 | 中文字幕久久精品 | 中国美女一级黄色片 | 久久久人成影片一区二区三区 | av av在线| 亚洲免费在线 | 91免费高清视频 | 九九色九九 | 91综合网 | 亚洲视频手机在线 | 欧美精品二区 | 国产91在线 | 亚洲 | 成人在线观看网址 | 亚洲精品粉嫩美女一区 | 91精品国产91 | 国产精品污污视频 | 欧美高清视频一区 | 日韩在线播放网址 | 99久久99久久精品国产片果冰 | 中文字幕在线网 | 干干干操操操 | 亚洲一二三在线 | 精品视频在线免费观看 | 国产亚洲成av人片在线观看桃 | 亚洲精品一区二区冲田杏梨 | 亚洲v区 | 日本一区二区三区四区 | 一区二区三区四区不卡 | 欧美精品日韩精品 | 亚洲成人一区二区三区 | 一区免费观看 | 国产分类视频 | 免费久久精品 | 亚洲人人| 天堂久久天堂综合色 | 狠狠爱一区二区三区 | 成人av鲁丝片一区二区小说 |