menú de selección móvil permanecer en la opción de selección de URL actual
Frecuentes
Visto 136 equipos
2
jQuery:
$(function() {
$('select').change(function(){
var url = $(this).val();
window.location = url;
});
});
HTML:
<select>
<option value="http://www.coolwebsite.com.au/Sandbox/">Home</option>
<option value="http://www.coolwebsite.com.au/Sandbox/kitchen.php">Kitchens</option>
<option value="http://www.coolwebsite.com.au/Sandbox/fitouts.php">Shop Fitouts</option>
<option value="http://www.coolwebsite.com.au/Sandbox/officefitouts.php">Office Fitouts</option>
<option value="http://www.coolwebsite.com.au/Sandbox/Gallery/">Gallery</option>
<option value="http://www.coolwebsite.com.au/Sandbox/joinery.php">Joinery</option>
<option value="http://www.coolwebsite.com.au/Sandbox/jobs.php">Recent Jobs</option>
<option value="http://www.coolwebsite.com.au/Sandbox/contact.php">Contact Us</option>
</select>
It works just fine, but once the select option is clicked and new page appears, the select
box returns to 'Home' option, rather than current page.
Wondering how to keep this option selected.
2 Respuestas
2
Prueba esto:
$(function()
var url = window.location.href;
$('select option[value="'+url+'"]').prop("selected",true);
});
Respondido 12 Feb 14, 08:02
He's reloading the page. This will not work upon reload - paolo casciello
0
Since you're reloading the page, it's the code generating the page (in this case the PHP code) that must write the attribute selected
al correspondiente <option>
etiqueta.
<select>
<option value="http://www.coolwebsite.com.au/Sandbox/">Home</option>
<option value="http://www.coolwebsite.com.au/Sandbox/kitchen.php" selected>Kitchens</option>
...
</select>
Respondido 12 Feb 14, 08:02
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas jquery html forms mobile or haz tu propia pregunta.
Have I understood this right? You want to reload the page and the selected value on the new page should be set to what you selected from the previous? - Niklas
You will need to add the selected page as the selected value in the relevant php page. E.g. if you select
Kitchens
from home you will need to set the select inkitchen.php
leer<option selected value="http://www.coolwebsite.com.au/Sandbox/kitchen.php">Kitchens</option>
- Rob SchmueckerI am loading my mobile menu from a php include, the same php include throughout all pages so this solution wouldn't be optimal. - Coastal-Cam