简体   繁体   English

如何使用jQuery StickyForms重新加载多个选择框的值?

[英]How do I reload the values of multiple select boxes with jQuery StickyForms?

I'm using jquery stickyForms to make some form values sticky, so that the user's entered values are restored to a form when the user returns to that form. 我正在使用jquery stickyForms使某些表单值具有粘性,以便在用户返回该表单时将用户输入的值还原到该表单。

It's works great, except I can't get it to work with my multiple selects. 它很棒,但是我无法使其与多重选择一起使用。 I checked the cookies it creates, and it doesn't even set the right values. 我检查了它创建的cookie,甚至没有设置正确的值。 Looking at the code, it doesn't even appear to support multiple selects. 查看代码,它甚至似乎都不支持多选。

Can anyone help? 有人可以帮忙吗?

I took it upon myself to add support for multiple selects. 我自己承担了对多种选择的支持。 This works for me! 这对我有用!

I changed line 115 to: 我将第115行更改为:

}else if(this[i].type == "select-multiple"){
    var setVal = $(this[i]).val();
}

Then I added this after line 178: 然后我在第178行之后添加了它:

// Load multiples
if((this[i].type == "select-multiple") && val != "null" ){
    var val_list = val.split(",");
    var select_name = "#" + $(this[i]).attr("id");
    $(val_list).each(function(){
        $(select_name + " option[value="+this+"]").attr('selected','selected');
    });

}

It works! 有用! But mind you, I'm not an expert at javascript or jQuery, so if you have a more succinct solution or one with better performance, please let me know! 但是请记住,我不是javascript或jQuery的专家,所以如果您有一个更简洁的解决方案或性能更好的解决方案,请告诉我!

This is Ryan from JQByte, I wanted to let you know that we released version 1.0 of StickyForms today which includes support for multi-select and AJAX-processing forms. 我是JQByte的Ryan,我想告诉您,我们今天发布了StickyForms的1.0版,其中包括对多选和AJAX处理表单的支持。

http://www.jqbyte.com/StickyForms/ http://www.jqbyte.com/StickyForms/

We did incorporate your solution into the plugin, we thank you for your contribution! 我们确实将您的解决方案整合到了插件中,我们感谢您的贡献!

Cheers, Ryan 干杯,瑞安

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM