其他分享
首页 > 其他分享> > 动态datalist使用方法一例

动态datalist使用方法一例

作者:互联网

<input
	name="person_school"
	value="{$row[person_school]}"
	list="school_list"
	placeholder="请填写您的学校名称"
/>
<datalist id="school_list"></datalist>

<script>
$('[name=person_school]').bind('input propertychange', function () {
	var keyword = $(this).val().replace(' ', '')
	$('#school_list').empty()
	if (keyword != '') {
		$.getJSON('/Home/School/get_search_result', {
			keyword: keyword
		}, function (res) {
			$.each(res.data, function (index, item) {
				if (res.data.length > 1 || keyword != item.school_name) {
					$('#school_list').append('<option value="' + item.school_name + '"/>')
				}
			})
		})
	}
})
</script>

标签:function,school,keyword,datalist,一例,item,res,动态,data
来源: https://www.cnblogs.com/sunr/p/16670221.html