English 中文(简体)
JQuery级联插件可记住上次选择的状态
原标题:JQuery Cascade plugin to remember last selected state

我正在使用JQuery级联插件(此处

我有它,所以我可以在第一个下拉列表中选择一个图书部分,在第二个下拉列表中将填充章节。例如:

var list1 = [
            { When : 0 , Value : 0 , Text : Chapter 1 },
            { When : 0 , Value : 1 , Text : Chapter 2 },
            { When : 0 , Value : 2 , Text : Chapter 3 },
                            ...(snip..)

            { When : 1 , Value : 0 , Text : Appendix 1 },
            { When : 1 , Value : 1 , Text : Appendix 2 },
            { When : 1 , Value : 2 , Text : Appendix 3 },
                            ....(snip..)
];

function commonTemplate(item){
   return "<option value= " + item.Value + " >" + item.Text + "</option>";
}; 
function commonTemplate2(item) {
            return "<option value= " + item.Value + " >***" + item.Text + "***</option>"; 
        };
        
        function commonMatch(selectedValue) {
            return this.When == selectedValue; 
        };

然后调用:

jQuery(document).ready(function()
    {   
        jQuery("#section").cascade("#chapter",{                 
            list: list1,            
            template: commonTemplate,
            match: commonMatch          
        });
    });

我的表单预先填充了第0节及其相关章节。一切都很好——当我选择第2本书时,脚本会启动并在第二个下拉列表中填充第2本的章节等。

我的问题是:当我选择一本像“第2节,第3章”这样的书时,我希望加载该书和章节,而页面上的表单显示“第2章,第3节”。通过这种方式,用户可以快速进入第4章或其他内容。目前,当加载第3章第2节时,表单默认为“第1章第1节”,这是用户第一次到达页面时的默认表单值。

我的问题是:我第一次怎么能有默认值,但当用户提交表单时,页面会重新加载,记住表单中最后一个选定的部分/章节?

谢谢

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签