我有这两个剧本。第一个文件保存模型的存储,然后在页面刷新之后,将模型加载到下拉列表中,并将包含相应年份值的文本文件打开到第二个下拉列表中。
第二个人应该做同样的事情,一切都很好。存储正在保存,但下拉列表没有填充吗?是因为选项不在html中而没有显示在下拉列表中吗?
另外,是否有更有效的方法将这两者结合起来。我有一套6个下降都依赖于另一个,我想做同样的。
<script>
$(function() {
$('#vehic_sel_model').change(function() {
sessionStorage.setItem('model', this.value);
});
if(sessionStorage.getItem('model')){
$('#vehic_sel_model').val(sessionStorage.getItem('model'));
$("#vehic_sel_year").load("/v/vehicle-selection/cache/" + sessionStorage.getItem('model') + ".txt");
}
});
</script>
<script>
$(function() {
$('#vehic_sel_year').change(function() {
sessionStorage.setItem('year', this.value);
});
if(sessionStorage.getItem('year')){
$('#vehic_sel_year').val(sessionStorage.getItem('year'));
$("#vehic_sel_trim").load("/v/vehicle-selection/cache/" + sessionStorage.getItem('year') + ".txt");
}
});
</script>
发布于 2016-02-17 15:56:48
在从文本文件中提取时,我已经知道了如何做到这一点。我必须将sessionsotrage.GetItem绑定到.load:
$(function() {
$('#vehic_sel_model').change(function() {
sessionStorage.setItem('model', this.value);
});
$('#vehic_sel_year').change(function() {
sessionStorage.setItem('year', this.value);
if(sessionStorage.getItem('model')){
$('#vehic_sel_model').val(sessionStorage.getItem('model'));
$("#vehic_sel_year").load("/v/vehicle-selection/cache/" + sessionStorage.getItem('model') + ".txt", function(){
$('#vehic_sel_year').val(sessionStorage.getItem('year'));
});
发布于 2016-02-12 22:04:27
试试这个:
if(sessionStorage.getItem('year')){ // <-- Problem here. You've forgotten if statement bracket.
$('#vehic_sel_year').val(sessionStorage.getItem('year'));
$("#vehic_sel_trim").load("/v/vehicle-selection/cache/" + sessionStorage.getItem('year') + ".txt");
}
https://stackoverflow.com/questions/35372542
复制相似问题