jquery .change function
On our home page we have a drop down menu that takes you to a country specific page.
We are using the the jquery change
function to point the user to the correct country when the country is selected in a dropdown box.
If the user selects a country and and presses back开发者_运维百科 after viewing the country page, and then wishes to view the same country page again, they have to select another country, press back and then select the previous desired country. Any way around this?
$(document).ready(function() {
$('select.jumpmenu').change(function(){
if($(this).find("option:selected").val() != 'no_selection'){
$.ajax({
type: "GET",
url: "/countries/jsontariff/" + $(this).find("option:selected").val(),
success: function(html){
window.location = "/recommend/";
}
});
}
});
});
Try to reset the select onload:
$(document).ready(function(){$('#selectList option:first').attr('selected',true)})
I would execute the same code on page load.
executeCountrySelection() {
if($('select.jumpmenu').find("option:selected").val() != 'no_selection'){
$.ajax({
type: "GET",
url: "/countries/jsontariff/" + $(this).find("option:selected").val(),
success: function(html){
window.location = "/recommend/";
}
});
}
}
$(document).ready(function() {
//executes when the page loads
executeCountrySelection();
//then again when the select is changed
$('select.jumpmenu').change(function() { executeCountrySelection(); });
});
精彩评论