最近项目中遇到了一个用tooltip显示地市的一个功能点,具体功能如下:
但是在网上找了很久关于tooltip发送ajax请求的案例很少,随后,自己经过实践得出的过程如下:以便日后用到的时候可以看看
首先贴一下html代码:
点击(此处)折叠或打开
- 城市:
- ID
- ${item[\"id\"]==null?\" \":item[\"id\"]}
- ${item[\"regionname\"]==null?\" \":item[\"regionname\"]}
上述代码中的(${list})是迭代后台传过来的展示省份的列表,这个可以自己所以写;其中因为是动态生成的省份名称,以及省份的html元素,所以,在生成页面的时候就要把tooltip生成好,然后在点击所选省份后,发送省份ID到后台查询其下面的地市,将地市展现出来;具体js代码如下:
点击(此处)折叠或打开
- $(function (){
- var r=document.getElementsByName(\"activation\");
- for(var i=0;i
- $(\'#\'+r[i].id).tooltip({
- content: $(\'
- showEvent: \'click\',
- onUpdate: function(content){
- var id=$(this).attr(\'id\');
- content.panel({
- width: 200,
- border: false
- });
- },
- onShow: function(){
- //alert($(this).attr(\'id\'));
- var t = $(this);
- var id = $(this).attr(\'id\');
- $.post(\"<%=path%>/supplyDemandManager/selectCity\",{id:id},
- function(data){
- var jsonObj = JSON.parse(data);
- t.tooltip(\'tip\').empty();
- for (var one in jsonObj){
- t.tooltip(\'tip\').append(\"\"+jsonObj[one].regionname+\" \");
- }
- });
- t.tooltip(\'tip\').unbind().bind(\'mouseenter\', function(){
- t.tooltip(\'show\');
- }).bind(\'mouseleave\', function(){
- t.tooltip(\'hide\');
- });
- }
- });
- }
- });
至此,功能实现了;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25903968/viewspace-1680731/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/25903968/viewspace-1680731/