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

提交后保持選中的選擇框

Keep a Select Box Selected after Submit(提交后保持選中的選擇框)
本文介紹了提交后保持選中的選擇框的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

在我的網(wǎng)站上,用戶可以按流派過濾游戲.當(dāng)用戶從選擇框中選擇一種類型并點(diǎn)擊提交時,頁面使用 GET 來查看過濾器是什么.現(xiàn)在過濾器工作正常,問題是選擇框的選擇變?yōu)槟J(rèn)選擇(即全部".)

On my website, user's are allowed to filter games by Genre. When a user chooses a genre from the select box and hits submit, the page uses GET to see what the filter was. Now the filter works fine, the problem is that the select box's selection goes to the default one (Which says "All".)

我希望在用戶提交過濾請求后,選擇框?qū)⒃陧撁嬷匦录虞d后保留該選擇.

I want it so that after a user submits their filter request, the select box will keep that selection after the page reloads.

我只能想到一種方法來做到這一點(diǎn),但它需要將 PHP 添加到每個選項(xiàng)中.有沒有更簡單的方法可以用 PHP 或 jQuery 來做到這一點(diǎn)?

There's only one way I could think of to do this but it would require adding in PHP into every option there is. Are there any simpler ways to go about doing this with PHP or jQuery?

推薦答案

假設(shè)你正在做一個完整的表單提交,選擇的選項(xiàng)只會對服務(wù)器端代碼可用,一旦它返回給客戶端使用 jQuery 你不會有那個(除非你在表單提交之前嘗試使用 cookie,但是 bleh).

Assuming you're doing a full form submit the selected option is only going to be available to the server-side code, once it gets back to the client to use jQuery you won't have that (unless you try to use cookies before the form submit, but bleh).

我會在選項(xiàng)標(biāo)簽中使用 PHP,如果選項(xiàng)與所選選項(xiàng)匹配,則回顯 selected="selected".

I'd use PHP in the option tag and echo selected="selected" if the option matches up with the selected option.

如果你想避免大量重復(fù)的代碼,為什么不做這樣的事情:

If you want to avoid a lot of duplicated code why not do something like this:

<select name="test">
<?php
$options = array(1 => 'Option 1', 2 => 'Option 2', 3 => 'Option 3');
foreach ($options as $key => $value) { 
   echo '<option value="' . $key . '"' . ($key == $_GET["test"] ? ' selected="selected"' : '') . '>' . $value . '</option>';
} ?>
</select>

這篇關(guān)于提交后保持選中的選擇框的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗(yàn)證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產(chǎn)品中添加一個將更改價(jià)格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 日本免费观看视频 | 91视频在线 | 国产操操操 | 在线免费黄色网址 | 成人深夜福利 | 日本www视频 | 国产一区久久 | 日韩不卡在线观看 | 国产乱人乱偷精品视频 | 欧美日韩免费 | 国产欧美久久久 | 久久亚洲精品视频 | 亚洲17p| 五月天激情视频 | 五月天婷婷社区 | 香蕉成人| 午夜婷婷 | 少妇搡bbbb搡bbb搡澳门 | 天堂a在线 | 日本黄色录像 | 四虎影院在线免费观看 | 激情五月综合网 | 欧美亚洲自拍偷拍 | 久久成人免费视频 | 色av导航 | 欧美日韩精品 | 99热国产 | 欧美精品亚洲 | 欧美成人一级片 | 亚洲天堂网在线观看 | 成人在线国产 | 国产精品日韩精品 | 欧美福利一区二区 | 色一情一乱一伦一区二区三区 | 亚洲午夜一区 | 婷婷色在线| 日韩一区二区三免费高清在线观看 | 国产一区一区 | 日韩欧美国产高清91 | 一区二区国产视频 | 国产一二区 |