代码示例展现PHP二级联动菜单的实现
Lepaskan: 2016-06-13 11:11:19
asal
1888 orang telah melayarinya
对于初学者来说,
PHP二级联动菜单代码示例:
- script language = "JavaScript">
- var onecount;
-
onecount=0;
-
subcat = new Array();
-
?php
- mysql_connect("localhost","charles",
"charles"); - mysql_select_db( "_crm" );
-
$sql = "select * from site";
-
$result = mysql_query( $sql );
-
$count = 0;
-
while($res = mysql_fetch_row($result)){
-
?>
-
subcat[ ?php echo $count ?>] = new Array
(" ?php echo $res[0]?>"," ?php echo
$res[2]?>"," ?php echo $res[1]?>");
-
?php
- $count++;
- }
-
echo "onecount=$count;";
-
?>
- //联动函数
- function changelocation(locationid)
- {
-
document.myform.ctype.length = 0;
-
var locationidlocationid=locationid;
- var i;
-
for (i=0;i onecount; i++)
- {
- if (subcat[i][2] == locationid)
- {
-
//var newnewOption1=new Option(subcat[i]
[1], subcat[i][0]);
- //document.all.ctype.add(newOption1);
- document.myform.ctype.options[document.
myform.ctype.length] = new Option(subcat
[i][1], subcat[i][0]); - }
- }
- }
-
/script>
-
form method="post" name="myform"
action="ru_query.php">
-
select name="type" onChange="changelocation(
document.myform.type.options[document.myfo
rm.type.selectedIndex].value)" size="1">
-
option selected value="">main /option>
-
?php
-
$sql = "select * from entreprise";
-
$result = mysql_query( $sql );
-
while($res = mysql_fetch_row($result)){
-
?>
-
option value="">
-
?php echo $res[1]; ?> /option>
-
?php } ?>
-
/select>
-
select name="ctype">
-
option selected value="">sub /option>
-
/select>
-
input type="submit" name="Submit" value="search">
-
/form>
以上代码就是PHP二级联动菜单的具体实现方法。
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31
Topik-topik yang berkaitan
Lagi>