Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 记住从搜索模块选择列表中选择的选项_Javascript_Forms_Select_Jquery Plugins_Cookies - Fatal编程技术网

Javascript 记住从搜索模块选择列表中选择的选项

Javascript 记住从搜索模块选择列表中选择的选项,javascript,forms,select,jquery-plugins,cookies,Javascript,Forms,Select,Jquery Plugins,Cookies,我有一个搜索表单,有多个选择列表。 我需要记住用户的最后选择,并在下一页将其设置为“默认”值。 我正在使用Jquery Cookie插件,但它只记住一个列表中的一个选择。 我怎样才能记住所有的选择? 这是一个示例形式: <form action="/component/sobipro/" method="post" id="XTspSearchForm141" > <input type="submit" id="XTtop_button" name="sear

我有一个搜索表单,有多个选择列表。 我需要记住用户的最后选择,并在下一页将其设置为“默认”值。 我正在使用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>

---Seleziona Localitá-
罗马
巴黎
---塞莱齐奥纳·斯蒂勒--
阿尔特
生意
以下是脚本:

<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>

jQuery(函数(){
jQuery('XTspSearchForm141')。提交(函数(e){
if(jQuery.cookie('my_cookie')){jQuery.cookie('my_cookie',null)}
cookie('my_cookie','my_value',{expires:30});
});
});
var$c=jQuery.noConflict();
//检查是否已设置cookie
如果($c.cookie('memory_select')!=null){
//将与cookie设置相对应的选项设置为selected
$c('.XTSPSearchSelect选项[value=“'+$c.cookie('memory_select')+''“]).attr('selected','selected');
}
//选择新选项时,将触发该选项
$c('.XTSPSearchSelect').change(函数(){
//更改选项时,将设置新cookie
$c.cookie('memory_select',$c('.XTSPSearchSelect选项:selected').val(),{expires:90,path:'/');
});

有什么想法吗?

要获得指导,您可以看看这个jquery插件,您好,谢谢您的回复。这个插件看起来不错,但我在互联网上找不到任何支持。这是一个非常简单的插件,带有ok类型的文档,如果你有任何疑问,可以在stackoverflow中询问。嗨,我更新了这个问题,我只记得一个选择列表,但不记得全部