码迷,mamicode.com
首页 > 其他好文 > 详细

easyui combobox 动态加载的两种方法

时间:2017-12-26 19:01:54      阅读:521      评论:0      收藏:0      [点我收藏+]

标签:post   asc   box   new   false   select   reload   func   选中   

reload 方法 

javascript代码

//指定id 和 text 否则始终选择第一个 $(‘#contact_city‘).combobox({ valueField:‘id‘, textField:‘text‘ }); $(‘#contact_province‘).combobox({ onSelect: function (data) {var url = "Ajax-index.php?module=Contact&action=Ajax_Contact_Province_Change"+"&contact_province=" +data.text; $(‘#contact_city‘).combobox(‘reload‘, url); } });
php代码 

$province
=trim($_GET[‘contact_province‘]); $select="SELECT p.province,c.id,c.city,p.provinceid from province as p JOIN city as c ON p.provinceid = c.provinceid where p.province=‘" . $province . "‘";
     $result=$db->query($select); $Select_Option=""; while($row=$db->fetch_array($result)){ $key=$row[1]; $value=$row[2]; if($Select_Option==""){ $Select_Option= ‘{"id":"‘.$key.‘","text":"‘.$value.‘"}‘ ; }else{ $Select_Option=$Select_Option .",". ‘{"id":"‘.$key.‘","text":"‘.$value.‘"}‘ ; } } $Select_Option="[" . $Select_Option ."]"; echo $Select_Option;

 

loadData 方法

javascript 

$(function(){ $(‘#contact_city‘).combobox({ valueField:‘id‘, textField:‘text‘, editable:false //是否可编辑 }); }) $(document).ready(function () { $("#contact_province").combobox({ onChange: function (newVal,oldVal) { var contact_province=newVal; $.ajax({ type: "POST", url: "Ajax-index.php?module=<{$module_name}>&action=Ajax_Contact_Province_Change", dataType: "json", data: {"contact_province":contact_province }, beforeSend: function(){ //$(‘<div id="msg" />‘).addClass("loading").html("加载中...").css("color","#999").appendTo(‘.sub1‘); }, success: function(json){ if(json.success==1){ //alert(json.msg); var data = $.parseJSON(json.msg); $("#contact_city").combobox("loadData", data); $("#contact_city ").combobox(‘select‘,data[0].text);//默认选中第一项 }else{ $.messager.alert(‘消息‘,‘数据加载失败!‘,‘error‘); return false; } } }); } }); });

PHP代码 

$province
=trim($_POST[‘contact_province‘]); $select="SELECT p.province,c.city,p.provinceid from province as p JOIN city as c ON p.provinceid = c.provinceid where p.province=‘" . $province . "‘"; $result=$db->query($select); $Select_Option=""; while($row=$db->fetch_array($result)){ $value=$row[1]; if($Select_Option==""){ $Select_Option= ‘{"id":"‘.$value.‘","text":"‘.$value.‘"}‘ ; }else{ $Select_Option=$Select_Option .",". ‘{"id":"‘.$value.‘","text":"‘.$value.‘"}‘ ; } } $Select_Option="[" . $Select_Option ."]"; $arr[‘success‘] = 1; $arr[‘msg‘] = $Select_Option; echo json_encode($arr);

 

easyui combobox 动态加载的两种方法

标签:post   asc   box   new   false   select   reload   func   选中   

原文地址:https://www.cnblogs.com/hailexuexi/p/8119439.html

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