当我选择一个选项时,这是我的代码,被选中。当我转到下一页并返回同一页面时,不会出现所选的值。
$("#purpose-of").selectmenu({
select: function(event, ui) {
if ($('#purpose-of option:selected').val() != 0) {
$('.purpose-of-row').find('.error-message').hide();
$('.purpose-of-row').find('.form-inner-field').removeClass('addRed');
}
}
});
答案 0 :(得分:0)
如果要离开,您需要跟踪状态,即存储值。有多种方法可以做到这一点:
以下是使用sessionStorage处理此问题的代码示例:
$("#purpose-of").selectmenu({
select: function(event, ui) {
if ($('#purpose-of option:selected').val() != 0) {
//Save value for later use
sessionStorage.setItem("purpose-of", $(this).val());
$('.purpose-of-row').find('.error-message').hide();
$('.purpose-of-row').find('.form-inner-field').removeClass('addRed');
}
}
});
$(document).ready(function() {
//Check when the page loads if value is stored and assign it to control if available
if (sessionStorage.getItem("purpose-of")) {
$('#purpose-of').val(sessionStorage.getItem("purpose-of"));
}
});
JSFiddle - 按运行模拟导航