码迷,mamicode.com
首页 > Web开发 > 详细

jquery json遍历和动态绑定事件

时间:2014-08-18 16:12:02      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   os   io   数据   ar   

<div id=‘tmpselectorList‘ style=‘border: 1px solid grey;max-height: 150px;position:absolute;text-align: left; overflow: auto;background:white;width:153px;‘>
                    
                </div>
<script type="text/javascript">
$(document).ready(function () { 
    $("#engineerName").change(function () { 
        //ajax获取数据库查询得到的数据 
        var name = $("#engineerName").val(); 
        if(name != ""){
            $.ajax({ 
                type: "get", 
                dataType: "json",
                url:"${contextPath}/carUpload/enginNameByLike/" + name +"?random="+Math.random(), 
                success: function (result) {  
                    //清空原来的旧数据
                    $("#tmpselectorList").empty();
                    
                    var html = "<ul class=‘ui-menu‘ style=‘cursor: pointer;‘>";
                     
                    //json数据遍历
                    $.each( result.data, function(index,item){ 
                        //alert("index:"+index+", item:"+ item);
                        html += "<li>"+item+"</li>"; 
                    });
                    
                    html += "</ul>";
                    $("#tmpselectorList").append(html);

                 } 
            }); 
        }
    });  
    
    //jquery动态绑定事件
    $("#tmpselectorList").on("click","ul li",function(){  
        //赋予值
        $("#engineerName").val( $(this).text() );
    }) ;
});
</script>

 

jquery json遍历和动态绑定事件,布布扣,bubuko.com

jquery json遍历和动态绑定事件

标签:style   blog   color   java   os   io   数据   ar   

原文地址:http://www.cnblogs.com/simpledev/p/3919584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!