如何在条件上将tokeninput参数设置为动态

时间:2013-01-12 07:44:15

标签: javascript jquery jquery-tokeninput

我正在使用tokeninput jquery与asp.net进行自动完成。

http://loopj.com/jquery-tokeninput/

我有一个文本框,搜索参数是有条件的。这个jquery是在加载时渲染的。有一个复选框,如果选中复选框,搜索参数将被更改,如果未选中复选框,则搜索参数是默认参数。我已将此调用为就绪状态。问题是当选中复选框时,搜索参数未更改。它只搜索一个条件作为默认条件。在ckeckbox上单击IsPastClass更改为true或false。

  $(document).ready(function() {
        $("#txtStudentTokenSearch").tokenInput("../Handlers/TestAutoCompleteHandler.ashx?SearchType=Patient&IsPastClass=false", {
            theme: "facebook",
            tokenDelimiter: "|",
            preventDuplicates: true,
            onAdd: function(item) { removeTokenDuplicate('#txtStudentTokenSearch', item); btnLoadStudent.Focus(); }
        });
});

任何人都可以告诉我如何在条件下设置tokeninput参数。

感谢。

2 个答案:

答案 0 :(得分:0)

尝试

$(document).ready(function() {
    $('.checkbox').change(function(){
        var IsPastClass = this.checked;
        $("#txtStudentTokenSearch").tokenInput("clear");
        $("#txtStudentTokenSearch").tokenInput("../Handlers/TestAutoCompleteHandler.ashx?SearchType=Patient&IsPastClass="+IsPastClass , {
            theme: "facebook",
            tokenDelimiter: "|",
            preventDuplicates: true,
            onAdd: function(item) { removeTokenDuplicate('#txtStudentTokenSearch', item); btnLoadStudent.Focus(); }
        });
    });
    $('.checkbox').trigger('change');
});

希望它有所帮助。

答案 1 :(得分:0)

您可以非常轻松地将tokenInput与ajax和handler一起使用 你可以从github下载例子 https://github.com/yanivsuzana/jquery-tokeninput-ajax-asp.net-vb