我正在使用jQuery UI自动完成功能,并且试图限制多个结果。基本上,我正在构建一个PM系统,我在to域使用自动完成功能。但是我试图限制可以发送一条消息的人数。因此,例如将最大选择限制为25。
有什么办法可以限制这个?还有关于视觉指示器达到最大值的想法吗?
select: function( event, ui){
var terms = split( this.value );
if(terms.length <= 2)
{
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
else
{
$(this).effect("highlight", {}, 1000);
$(this).addClass("red");
$("#warnings").html("<span style='color:red;'>Max people reached</span>");
return false;
}
}
参考方案
通过收听events可以很容易地实现这一点。例如,您可以通过adding class将颜色设置为红色,并删除类以使其自动完成。我认为您可以通过一点点的努力自己完成此任务。
select: function( event, ui ) {
var terms = split( this.value );
if(terms.length <= 2) {
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
} else {
var last = terms.pop();
$(this).val(this.value.substr(0, this.value.length - last.length - 2)); // removes text from input
$(this).effect("highlight", {}, 1000);
$(this).addClass("red");
$("#warnings").html("<span style='color:red;'>Max people reached</span>");
return false;
}
}
附注:我还认为,由于google,这些插件之一可能是合适的:
https://github.com/loopj/jQuery-Tokenizing-Autocomplete-Plugin
在我看来看起来不错:
单击链接以查看live demo。
http://net.tutsplus.com/tutorials/javascript-ajax/how-to-use-the-jquery-ui-autocomplete-widget/
Facebook style JQuery autocomplete plugin
在我的PHP文件中,我将一些变量从输入框传递到链接中,该链接通过jQuery的ajax load函数在其URL中使用该变量加载页面。整个系统运行良好,但仅适用于单字变量。每当涉及到空格时,我的Ajax通话都会中断。我假设这是一个编码问题,但是我也有一些疑问。基本上,它归结为我的PHP文件中的这一行代码,这导致了混乱。是否有可能找出格式是否正确,或者为什么在多…
jQuery-找不到Ajax网址 - php好的,我敢肯定这确实很容易,而且我很愚蠢,但是似乎并不能深入了解它。我试图从我的js文件“ custom.js”中对“ helpers.php”中的某些代码进行简单的AJAX调用。但是,我仍然收到404错误,因为我似乎并没有正确遍历文件夹,尽管我确信我正在...我的文件夹结构如下:html index.php js/ custom.js includes h…
jQuery Ajax PHP重定向到另一个页面 - phpJavaScript文件:$.ajax({ type: "POST", url: "ajax.php", data: dataString, success: function(r) { $("#div").html(r); } }); 我想在成功的情况下将页面重定向到new.php,所以在我使用a…
jQuery Ajax和php类 - php我正在尝试学习如何在php中使用oop。我对jQuery也很陌生。是否可以向php类方法发出Ajax请求?我只将Ajax请求发送到专门用于此目的的文件,并且返回我需要的数据。 参考方案 简短答案:不可以。长答案:Ajax只是一个使用JavaScript从浏览器发出HTTP请求而无需离开页面的术语。您唯一可以“呼叫”的是URL。您可以编写PHP以根据URL来执…
jQuery ajax()返回json对象,但未正确警告 - php为什么无法使用data [0] .id返回ID? $(document).ready(function(){ $.ajax({ type: 'POST', dataType: "json", url: '<?php echo matry::base_to('tests/map_it'…