如何在 Ajax AutoComplete 中为 jQuery 传递额外参数?
你好,我在我的jquery中使用Ajax AutoComplete for jQuery
,我正在使用
options = { serviceUrl: "<? echo $this->config->item('base_url'); ?>index.php/welcome/autocomplete" };
a = $('#query').autocomplete(options);
我看到我可以传递额外的参数,
var a = $('#query').autocomplete({
serviceUrl:'service/autocomplete.ashx',
minChars:2,
delimiter: /(,|;)\s*/, // regex or character
maxHeight:400,
width:300,
zIndex: 9999,
deferRequestBy: 0, //miliseconds
params: { country:'Yes' }, //aditional parameters
noCache: false, //default is false, set to true to disable caching
// callback function:
onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data); },
// local autosugest options:
lookup: ['January', 'February', 'March', 'April', 'May'] //local lookup values
});
所以我想创建n个新参数并像这样传递它
var a = $('#query2').autocomplete({
serviceUrl: "<? echo $this->config->item('base_url'); ?>index.php/welcome/autocomplete",
id:'query2'
});
我如何从自动完成代码访问该额外参数?我想将该 id 添加到我的
.autocomplete-w1
初始位置,它看起来像这样,
<div class="autocomplete-w1"></div>
我想更改它以
<div id="jquery2" class="autocomplete-w1"></div>
请帮助........................................ ...
更新
我尝试将我的 id 参数添加到此函数中,
function Autocomplete(el, options) {
this.el = $(el);
this.el.attr('autocomplete', 'off');
this.suggestions = [];
this.data = [];
this.badQueries = [];
this.selectedIndex = -1;
this.currentValue = this.el.val();
this.intervalId = 0;
this.cachedResponse = [];
this.onChangeInterval = null;
this.ignoreValueChange = false;
this.serviceUrl = options.serviceUrl;
this.isLocal = false;
this.options = {
autoSubmit: false,
minChars: 1,
maxHeight: 300,
deferRequestBy: 0,
width: 0,
highlight: true,
params: {},
fnFormatResult: fnFormatResult,
delimiter: null,
zIndex: 9999,
id:'test'
};
this.initialize();
this.setOptions(options);
}
我给出了默认值 test
。当我警告 $this.options.id
我总是得到 'test'
我通过 jquery2
没有得到的值。那里有什么问题???
hi i am using Ajax AutoComplete for jQuery
in my jquery i am using
options = { serviceUrl: "<? echo $this->config->item('base_url'); ?>index.php/welcome/autocomplete" };
a = $('#query').autocomplete(options);
i saw that i can pass extra parameters like
var a = $('#query').autocomplete({
serviceUrl:'service/autocomplete.ashx',
minChars:2,
delimiter: /(,|;)\s*/, // regex or character
maxHeight:400,
width:300,
zIndex: 9999,
deferRequestBy: 0, //miliseconds
params: { country:'Yes' }, //aditional parameters
noCache: false, //default is false, set to true to disable caching
// callback function:
onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data); },
// local autosugest options:
lookup: ['January', 'February', 'March', 'April', 'May'] //local lookup values
});
so i want to create n new parameter and pass it like this
var a = $('#query2').autocomplete({
serviceUrl: "<? echo $this->config->item('base_url'); ?>index.php/welcome/autocomplete",
id:'query2'
});
How can i access that extra parameter from the autocomplete code ?? i want to add that id to my
.autocomplete-w1
initially it looks like this
<div class="autocomplete-w1"></div>
i want to change it to
<div id="jquery2" class="autocomplete-w1"></div>
please help................................
UPDATE
i tried to adding my id parameter to this function
function Autocomplete(el, options) {
this.el = $(el);
this.el.attr('autocomplete', 'off');
this.suggestions = [];
this.data = [];
this.badQueries = [];
this.selectedIndex = -1;
this.currentValue = this.el.val();
this.intervalId = 0;
this.cachedResponse = [];
this.onChangeInterval = null;
this.ignoreValueChange = false;
this.serviceUrl = options.serviceUrl;
this.isLocal = false;
this.options = {
autoSubmit: false,
minChars: 1,
maxHeight: 300,
deferRequestBy: 0,
width: 0,
highlight: true,
params: {},
fnFormatResult: fnFormatResult,
delimiter: null,
zIndex: 9999,
id:'test'
};
this.initialize();
this.setOptions(options);
}
i gave a default value test
. when i alert $this.options.id
i always getting 'test'
the value i passig jquery2
is not getting . what is the problem there ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯。我已经解决了。
添加了额外的参数 id,
我在我的
jquery.autocomplete.js
中一样,
就像现在我可以将它添加到 div 的 id 中
谢谢...... ....:) :) :D
hmmm. i have solved it .
i added extra parameter id
in my
jquery.autocomplete.js
ini get that parameter like
now i can add it to div's id
thanks.................... :) :) :D