我有一个下拉值列表,它应该在javascript中每个会话提醒一次popup。在更改时如何警告下拉列表中的任何值,但它应该是一个选择值(下拉列表)。我试图提醒。请建议如何使用javascript中的会话存储来实现它。
jQuery("#dim_height").on('focus', function() {
// Store the current value on focus and on change
previous = this.value;
}).change(function() {
var r1 = confirm("Are you sure want to change the template?");
if (r1 == true) {
calci_width();
} else {
jQuery(this).val(previous);
return;
}
//reset_template(previous);
//calci_width();
});
jQuery("#dim_width").on('focus', function() {
// Store the current value on focus and on change
previous = this.value;
}).change(function() {
var r = confirm("Are you sure want to change the template?");
// console.log(r);
if (r == true) {
calci_width();
} else {
jQuery(this).val(previous);
return;
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="dim_width" id="dim_width" class="drop">
<option value="8">8</option>
<option value="12">12</option>
<option value="18">18</option>
<option value="24">24</option>
<option value="36">36</option>
<!-- <option value="48">48</option>
<option value="72">72</option>
<option value="84">84</option>
<option value="96">96</option> -->
</select>
<select name="dim_height" id="dim_height" class="drop">
<option value="8">8</option>
<option value="12">12</option>
<option value="18">18</option>
<option value="24">24</option>
<!-- <option value="36">36</option>
<option value="48">48</option> -->
</select>
&#13;
答案 0 :(得分:0)
以下是如何使用Cookie为每个会话发出一次警报的示例:
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script><!-- notice jquery version change-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-
cookie/1.4.1/jquery.cookie.min.js"></script><!-- added cookie plugin-->
<select name="dim_width" id="dim_width" class="drop">
<option value="8">8</option>
<option value="12">12</option>
<option value="18">18</option>
<option value="24">24</option>
<option value="36">36</option>
</select>
然后使用jquery:
$('#dim_width').on('change', function(){
if (typeof $.cookie('alerted') === 'undefined'){//does cookie exist?
var Selected = $('#dim_width').val();
alert(Selected); //if not alert value
$.cookie("alerted", 1); //then set cookie, will expire one browser closes
}
})