This article mainly introduces how to retain the selected value without returning the default value after the HTML drop-down menu is submitted. Although the method is simple, it is more practical. Friends in need can refer to it
<html> <body> <?php // 获取select值 $select_value = isset($_GET['select']) ? $_GET['select'] : ''; ?> <form action="?"> <select name="select"> <option value="">default</option> <option value="option1" <?php // 如果在上面获取的值和这个option里的值一样, // 就打印selected,让这个option默认被选中 echo $select_value == 'option1' ? 'selected' : '' ?>>option1</option> </select> <input type="submit" value="submit" /> </form> </body> </html>
Each option must be With this script, if there are multiple, you can print them in a loop.
For more html drop-down menus, after submission, the selected value is retained without returning to the default value. For related articles, please pay attention to the PHP Chinese website!