ITeye博客

下拉列表功能获取数据添加到select表中

wyr123789 · 2017-03-14 15:41 · 前端 · 前端,js,jquery · Web前端 · Markdown

<script src="jquery-1.7.2.min.js"></script>
<script>

	$(function(){
		/*数组添加到下拉列表中
		 * var _mozi=;
		$.each(_mozi,function(key,val){
	    //回调函数有两个参数,第一个是元素索引,第二个为当前值
	    var num=key+1;
	    $('.textPrepend').prepend('<option value ="'+key+'">'+val+'</option>');
	})*/
	/*json数组读取数据添加到select下拉列表中
	 * var people = { "programmers": }
	people = eval(people.programmers);
	for(var i=0; i<people.length; i++)
	{
	$('.textPrepend').prepend('<option value ="'+*+'">'+people*.firstName+'</option>');
	}*/
	/*遍历json对象添加到select下拉列表中
	 * var people= 
	$.each(people, function(idx, obj) {
	    $('.textPrepend').prepend('<option value ="'+idx+'">'+obj.firstName+'</option>');
	});*/
	});

	$('.textclas').on('click',function(){
		alert('取到的数值是:'+$('.textPrepend').val());
	});
</script>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。