`
Shou_senn
  • 浏览: 1659 次
文章分类
社区版块
存档分类
最新评论

datalist实现输入联想

    博客分类:
  • web
阅读更多

用HTML5的datalist属性可以比较简单的实现输入联想功能,代码如下:

 

<html>
	<head>
	<script type="text/javascript" src="jquery-1.10.1.js"></script>
<script>
//datalist添加联想内容
$(function($){
$("#associate option").remove();
//数据
var str = eval('[{"message":1},{"message":2}]');
//绑定到associate
 $.each(str, function() {
       $("#associate").append("<option value='"+this.message+"'>");
    });
})
</script>
	</head>
	<body>
		<input type="text" list="associate">
		<datalist id="associate">
		</datalist>
	</body>
</html>

 

 

 

1
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics