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

提交后保持選中的選擇框

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

問題描述

限時送ChatGPT賬號..

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

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".)

我希望在用戶提交過濾請求后,選擇框將在頁面重新加載后保留該選擇.

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

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

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?

推薦答案

假設你正在做一個完整的表單提交,選擇的選項只會對服務器端代碼可用,一旦它返回給客戶端使用 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).

我會在選項標簽中使用 PHP,如果選項與所選選項匹配,則回顯 selected="selected".

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

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

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>

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

【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(liá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 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產(chǎn)品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 欧洲国产精品视频 | 一区二区三区视频在线 | 中文字幕日本一区二区 | 国产精品视频一区二区三区 | 国产乱码精品一品二品 | 国产日韩一区二区三区 | 国产999精品久久久久久 | 午夜丰满少妇一级毛片 | 最新91在线 | 一区二区三区电影网 | 久久久久久综合 | 断背山在线观看 | 国产精品久久毛片av大全日韩 | 在线视频中文字幕 | 日本三级网站在线观看 | 综合色播| 欧美日韩久 | 久久99精品久久久久久琪琪 | 精产国产伦理一二三区 | 欧美国产精品一区二区三区 | 国产一级在线 | av在线免费观看网站 | 欧美精品综合 | 一区二区三区在线电影 | 久久久久久久一级 | 国产一区久久 | 国产成人精品a视频一区www | 国产一区二区三区 | a级大毛片 | 97精品国产97久久久久久免费 | 久久久久免费精品国产 | 成人av网站在线观看 | 一级片毛片 | 久久91精品久久久久久9鸭 | 亚洲一区二区 | 亚洲天堂一区二区 | 黄色国产在线视频 | 97久久精品午夜一区二区 | 毛片免费视频 | 亚洲视频 欧美视频 | 天天干天天色 |