本文介绍了如何用@和$创建一个Bootstrap建议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我在文本框中有一些自动完成代码,标志为@和$



< script> 
var users = [
{username:'lodev09',fullname:'Jovanni Lo'},
{username:'foo',fullname:'Foo User'},
{username:'bar',fullname:'Bar User'},
{username:'twbs',fullname:'Twitter Bootstrap'},
{username:'john',fullname:'John Doe '},
{用户名:'jane',全名:'Jane Doe'},
];

var stocks = [
{用户名:'BUMI',全名:'Bumi Prosperindo'},
{用户名:'BMRI',全名:'Bank Mandiri'},
{用户名:'BBRI',全名:'银行BRI'},
{用户名:'BBCA',全名:'银行BCA'},
{用户名:'DBSA',全名:'银行DBS'},
{用户名:'OPRS',全名:'Siloam医院'},
];

$('#example-1')。keypress(function(event){
if(event.which == 36)
{
$(' #example-1')。suggest('$',{
data:stocks,
map:function(stock){
return {
value:stock.username,
text:''+ stock.username +'< small>'+ stock.fullname +'< / small>'
}
},
过滤器:{
casesensitive:false,
limit:8
}
})
}
else
{
$( '#example-1')。suggest('@',{
data:users,
map:function(user){
return {
value:user.username,
text:''+ user.username +'< small>'+ user.fullname +'< / small>'
}
},
filter:{
casesensitive:false,
limit:8
}
})
}
});

< / script>





但是我发现,此代码仅适用于标志@没有使用$的符号。



我想要的是@和$在文本框中一起工作。 />


例如:

@alpha将杀死@BUMI



谢谢。

解决方案




Here i've some code for autocomplete in textbox with the sign of "@" and "$"

<script>
	var users = [
		{username: 'lodev09', fullname: 'Jovanni Lo'},
		{username: 'foo', fullname: 'Foo User'},
		{username: 'bar', fullname: 'Bar User'},
		{username: 'twbs', fullname: 'Twitter Bootstrap'},
		{username: 'john', fullname: 'John Doe'},
		{username: 'jane', fullname: 'Jane Doe'},
	];

	var stocks = [
		{username: 'BUMI', fullname: 'Bumi Prosperindo'},
		{username: 'BMRI', fullname: 'Bank Mandiri'},
		{username: 'BBRI', fullname: 'Bank BRI'},
		{username: 'BBCA', fullname: 'Bank BCA'},
		{username: 'DBSA', fullname: 'Bank DBS'},
		{username: 'OPRS', fullname: 'Siloam Hospital'},
	];

	$('#example-1').keypress(function(event) {
		if( event.which == 36 )
		{
			$('#example-1').suggest('$', {
				data: stocks,
				map: function(stock) {
					return {
						value: stock.username,
						text: ''+stock.username+' <small>'+stock.fullname+'</small>'
					}
				},
				filter: {
					casesensitive: false,
					limit: 8
				}
			})
		}
		else
		{
			$('#example-1').suggest('@', {
				data: users,
				map: function(user) {
					return {
						value: user.username,
						text: ''+user.username+' <small>'+user.fullname+'</small>'
					}
				},
				filter: {
					casesensitive: false,
					limit: 8
				}
			})
		}
	});

</script>



but i've found, this code that work only for the sign "@" not working with the Sign of "$".

what i want is the "@" and "$" is working together within the textbox.

example is :
"the @alpha is going to kill the @BUMI"

thanks.

解决方案




这篇关于如何用@和$创建一个Bootstrap建议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:31