久久久久久久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)
主站蜘蛛池模板: 九色 在线 | 亚洲一区二区高清 | 国产一区二区三区四区五区加勒比 | 性色的免费视频 | 亚洲第一天堂无码专区 | 欧美亚洲国产一区二区三区 | 亚洲精品久久久久avwww潮水 | av片在线观看网站 | 精品日韩在线观看 | 欧美日韩淫片 | 亚洲精品视频在线观看免费 | 日本一区二区三区四区 | 成人中文字幕在线观看 | 欧美成人a∨高清免费观看 欧美日韩中 | 国产二区精品视频 | 欧美在线一区二区三区 | 久久精品国产一区 | 中文字幕爱爱视频 | 国产成人精品一区二三区在线观看 | 欧美日韩专区 | 一级黄色网页 | 国产乱码精品一区二区三区忘忧草 | 国产美女久久久 | 在线观看成人av | 天堂一区二区三区 | 久久国产高清视频 | 欧美激情 一区 | 九九亚洲| 日本羞羞影院 | 免费观看一级视频 | 97久久精品 | 成人亚洲性情网站www在线观看 | 日韩电影a | 色视频欧美 | 狠狠操狠狠色 | 在线成人av | 精品99久久久久久 | 嫩草视频在线 | 激情国产 | 日韩精品极品视频在线观看免费 | 日本高清视频在线播放 |