Ajax做列表無(wú)限加載和Ajax做二級(jí)下拉選項(xiàng),供大家參考,具體內(nèi)容如下
//欄目Ajax做加載
public function ajaxlist(){
//echo "http://www.域名.com/index.php?a=Indexc=Indexm=ajaxlist";
//echo "hr>";
$data = Q('sum');
$where = array();
$where['cid'] = 33;
$rongyuList = M('content')->limit($data,2)->where($where)->select();
$data['stat'] = 1;
$data = $rongyuList;
$this->ajax($data);
//也可以手動(dòng)把想要的字段拼接成字符串
/*echo "[";
foreach($rongyuList as $k){
echo "{"."\""."title"."\"".":"."\"".$k['title']."\"".","."\""."description"."\"".":"."\"".$k['description']."\"".","."\""."cid"."\"".":"."\"".$k['cid']."\""."}".",";
}
echo "]";*/
}
具體頁(yè)面實(shí)現(xiàn):
script type='text/javascript'>
/*ajax*/
(function(){
//發(fā)送數(shù)據(jù)
var url = "__WEB__"+"?a=Indexc=Indexm=ajaxlist";
var oSum = '';
$('a.ajaxBut').click(function(){
oSum = $('div.zizhiListContBox>a').size();
$.post(url,{sum:oSum},function(result){
console.log(result);
eval("var info="+result);
for(var key in info){
oStr = "a href='"+"__WEB__"+"?a=Indexc=Indexm=contentmid=1cid=33aid="+info[key]['aid']+""+"'>h3 class='f100 f16 ts500'>"+info[key]['title']+"/h3>p>"+info[key]['description']+"/p>span class='b parb'>/span>/a>";
$('div.zizhiListContBox').append(oStr);
};
});
});
})();
/script>
Ajax 做二級(jí)選項(xiàng):
!-- 示例:HTML -->
dl class="pr keshi" >
dt class="pa">科室:/dt>
dd class="pa">
select name='keshi' class='m_keshi'>
option value='0'>--請(qǐng)選擇科室--/option>
/select>
select name='zhuanjia' class='m_zhuanjia'>
option>--請(qǐng)選擇專(zhuān)家--/option>
/select>
/dd>
/dl>
示例控制器:
//示例控制器
/* Ajax請(qǐng)求欄目列表 */
public function ajaxlanmu(){
$lanmuList = M('category')->where('pid=142')->select();
$this->ajax($lanmuList);
}
public function ajaxzhuanjia(){
$where = array();
$data = Q('sum');
$data = $data ? $data : 143;
$where['cid'] = $data;
$zhuanjiaList = M('guahao')->where($where)->select();
$this->ajax($zhuanjiaList);
}
示例:JS
script>
(function(){
var lanmuUrl = "__WEB__"+"?a=Indexc=Indexm=ajaxlanmu";
var zhuanjiaUrl = "__WEB__"+"?a=Indexc=Indexm=ajaxzhuanjia";
var oSum = oStr = oStr2 = oVal = oKong = info2 = oCid = '';
/* lanmu */
$.post(lanmuUrl,function(result){
eval("var info="+result);
for(var key in info){oStr += "option value='"+info[key]['catname']+"' cid='"+info[key]['cid']+"'>"+info[key]['catname']+"/option>";};
$('dl.keshi').find('select.m_keshi').append(oStr);
});
/* zhuanjia */
$('dl.keshi').find('select.m_keshi').change(function(){
oVal = $(this).find('option:selected').val();
if(oVal == 0){
$('dl.zhuanjia').find('select.m_zhuanjia').html("option>--請(qǐng)選擇專(zhuān)家--/option>");
}else{
oCid = $(this).find('option:selected').attr('cid');
$.post(zhuanjiaUrl,{sum:oCid},function(result){
eval("info2="+result);
oStr2 = '';//注意這里要清空第一次請(qǐng)求的數(shù)據(jù)
for(var key2 in info2){
oStr2 += "option value='"+info2[key2]['title']+"'>"+info2[key2]['title']+"/option>";
};
$('dl.zhuanjia').find('select.m_zhuanjia').html(oStr2);
});
};
});
})();
/script>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:- jQuery+AJAX實(shí)現(xiàn)無(wú)刷新下拉加載更多
- 用ajax動(dòng)態(tài)加載需要的js文件
- php+ajax+jquery實(shí)現(xiàn)點(diǎn)擊加載更多內(nèi)容
- php+ajax實(shí)現(xiàn)無(wú)刷新動(dòng)態(tài)加載數(shù)據(jù)技術(shù)
- jQuery 瀑布流 浮動(dòng)布局(一)(延遲AJAX加載圖片)
- Jquery仿淘寶京東多條件篩選可自行結(jié)合ajax加載示例
- jquery用ajax方式從后臺(tái)獲取json數(shù)據(jù)后如何將內(nèi)容填充到下拉列表
- java AJAX實(shí)現(xiàn)級(jí)聯(lián)下拉框
- ThinkPHP使用心得分享-ThinkPHP + Ajax 實(shí)現(xiàn)2級(jí)聯(lián)動(dòng)下拉菜單
- php+ajax做仿百度搜索下拉自動(dòng)提示框(有實(shí)例)