$dsql->SetQuery("SELECT evalue,ename from `ddmx_sys_enum` where egroup='center' AND evalue%500 = 0 order by disorder asc, evalue asc"); $dsql->Execute(); $enums = array(); $sort = 1 ; while($row = $dsql->GetArray()) { $options .= "<option value=\"{$sort}\">{$row['ename']}</option>\r\n"; $enums[] = $row['evalue']; $sort ++ ; } $count = count($enums); foreach($enums as $i=>$evalue) { |
$dsql->SetQuery("SELECT evalue,ename,link from `ddmx_sys_enum` where egroup='center' AND evalue > {$evalue} AND evalue < ({$evalue} + 500) order by disorder asc, evalue asc"); $dsql->Execute(); $sort = 0 ; $i++; while($row = $dsql->GetArray()) { $js .= "select2[". $i ."][{$sort}] = new Option(\"{$row['ename']}\", \"{$row['link']}\");\r\n"; $sort++; } } $html = ' <form name="frm"> <div class="city_sch"> <h2 class="f13">选择里您最近的学习中心</h2> <table width="190" height="128" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="51" align="center" valign="middle"><label> <select name="s1" onChange="redirec(document.frm.s1.options.selectedIndex)"> <option selected>点击选择城市</option> '. $options .' </select> </label></td> </tr> <tr> <td height="22" align="center" valign="middle"><label> <select name="s2" id="s2"> <option value="点击选择中心" selected>点击选择中心</option> </select> </label></td> </tr> <tr> <td height="55" align="center" valign="middle"><label> <input type="submit" name="button" id="button" value="马上提交" onclick="window.location=document.frm.s2.value;return false;"/> </label></td> </tr> </table> </div> </form> <script language="javascript"> var select1_len = document.frm.s1.options.length; var select2 = new Array(select1_len); for (i=0; i<select1_len; i++) { select2[i] = new Array(); } select2[0][0] = new Option("请选择", " "); '. $js .' function redirec(x) { var temp = document.frm.s2; for (i=0;i<select2[x].length;i++) { temp.options[i]=new Option(select2[x][i].text,select2[x][i].value); } temp.options[0].selected=true; } </script> '; $html = addslashes(str_replace(array("\r\n", '"'), array('', '\''), $html)); echo "document.write(\" $html \")"; ?> |
版权声明: 本站资源均来自互联网或会员发布,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!
转载请注明: dedecms +Js实现自定义二级联动