jquery与zend framework编写的联动选项效果
程序员文章站
2022-10-31 09:31:26
html部分:
<...
html部分:
<script type="text/javascript" src="/js/jquery.js"></script> <script type="text/javascript" src="/js/cxjl.js"></script> <script type="text/javascript" src="/js/jquery_duoxuan1.js"></script> MYTITLE
---请选择学院--- ---请选择专业---
jquery部分:
<script type="text/javascript"> $(document).ready(function(){ //联动下拉菜单 $("#college").load("/dyjsdp/college"); $("#college").change(function(){ $("#major").load("/dyjsdp/major","college="+$(this).val()); }); $("#major").change(function(){ $("#classes").load("/dyjsdp/class","major="+$(this).val()); }); }); </script>
zend framework部分://学院联动 public function collegeAction(){ //header("Content-Type:text/html;charset=utf-8"); header("Cache-Control:no-cache"); $colleges=new College(); $res=$colleges->fetchAll(); echo "--请选择学院--"; foreach ($res as $college){ echo "".$college['name'].""; } exit(); } //专业联动 public function majorAction(){ //header("Content-Type:text/xml;charset=utf-8"); header("Cache-Control:no-cache"); $college=$this->getRequest()->getParam("college"); //file_put_contents("G:/php/myenv/mylog.log",$college); $majors=new Major(); $db=$majors->getAdapter(); $sql=$db->quoteInto("select m.name from college c,major m where c.id=m.college_id and c.name=?", $college); $res=$db->query($sql)->fetchAll(); echo "---请选择专业---"; foreach ($res as $major){ echo "".$major['name'].""; } exit(); }