0

我有一个搜索表单,有多个选择列表。我需要记住用户的最后选择,并在下一页将其设置为“默认”值。我正在使用 Jquery Cookie 插件,但它只记住一个列表的一个选择。我怎样才能记住所有的选择?这是一个示例形式:

    <form action="/component/sobipro/" method="post" id="XTspSearchForm141" >
    <input type="submit" id="XTtop_button" name="search" value="Search" class="button" onclick="this.form.sp_search_for.focus();extSearchHelper141.extractFormValues();"/>
    <select id="XTfield_localita" name="field_localita" class="XTSPSearchSelect" >
    <option value=""> --- Seleziona Località  --- </option>
    <optgroup label="Italy">
    <option value="localita_option_1">Rome</option>
    </optgroup>
    <optgroup label="France">
    <option value="localita_option_2">Paris</option>
    </optgroup>
    </select>
    <select id="XTfield_stile" name="field_stile" class="XTSPSearchSelect" >
<option value=""> --- Seleziona Stile  --- </option>
    <option value="stile_option_1">Arte</option>
    <option value="stile_option_2">Business</option>
    </select>
    </form>

这是脚本:

<script text= type='text/javascript'> 

jQuery(function() {

    jQuery('XTspSearchForm141').submit(function(e) {
         if (jQuery.cookie('my_cookie') ) { jQuery.cookie( 'my_cookie', null) }
        jQuery.cookie('my_cookie', 'my_value', { expires: 30 });
    });
});

</script>


<script text= type='text/javascript'> 

var $c = jQuery.noConflict();
//checks if the cookie has been set
if($c.cookie('remember_select') != null) {
// set the option to selected that corresponds to what the cookie is set to
$c('.XTSPSearchSelect option[value="' + $c.cookie('remember_select') + '"]').attr('selected', 'selected');
}
// when a new option is selected this is triggered
$c('.XTSPSearchSelect').change(function() {
// new cookie is set when the option is changed
$c.cookie('remember_select', $c('.XTSPSearchSelect option:selected').val(), { expires: 90, path: '/'});
});

</script>

有任何想法吗?

4

0 回答 0