考虑:
<form method="get" action=""> <select name="name"> <option value="a">a</option> <option value="b">b</option> </select> <select name="location"> <option value="x">x</option> <option value="y">y</option> </select> <input type="submit" value="Submit" class="submit" /> </form>
提交表单时,如何确保下拉列表中的选定值保持选中状态?此表单位于WordPress(PHP)内部。
为了避免许多if-else结构,让JavaScript自动完成:
<select name="name" id="name"> <option value="a">a</option> <option value="b">b</option> </select> <script type="text/javascript"> document.getElementById('name').value = "<?php echo $_GET['name'];?>"; </script> <select name="location" id="location"> <option value="x">x</option> <option value="y">y</option> </select> <script type="text/javascript"> document.getElementById('location').value = "<?php echo $_GET['location'];?>"; </script>