我就想,这样的功能应该有现成的吧,
果不其然,一下就找到了,站在巨人的肩膀上果然很快:)
https://github.com/ichord/At.js
1 <link href="css/jquery.atwho.css" rel="stylesheet"> 2 <script src="http://code.jquery.com/jquery.js"></script> 3 <script src="js/jquery.caret.js"></script> 4 <script src="js/jquery.atwho.js"></script> 5 6 $('#inputor').atwho({ 7 at: "@", 8 data:['Peter', 'Tom', 'Anne'] 9 })
代码通俗易懂,简介明快