gpt4 book ai didi

javascript - 使用 JCombo 制作链式组合框

转载 作者:行者123 更新时间:2023-11-29 00:19:12 26 4
gpt4 key购买 nike

我想为我的代码寻求一些帮助,因为我当前的代码无法工作...我从这个网站找到了这个插件代码 click here ...截至目前,即使是第一个组合框过滤,所有内容都无法正常工作...有人可以帮助我让这段代码正常工作吗。

enter image description here

索引.php:

<!DOCTYPE html>
<html>
<head>
<title>test</title>
<script type="text/javascript" src="jquery/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="jquery.jCombo.min.js"></script>
<script type="text/javascript" src="jquery.jCombo.js"></script>
</head>
<body>
<form>
<select name="position" id="position"></select>
<select name="salary_grade" id="salary_grade"></select>
<select name="salary" id="salary"></select>
</form>
<script type="text/javascript">
$( document ).ready(function() {
$("#position").jCombo({ url: "getPosition.php", selected_value : '150' } );
$("#salary_grade").jCombo({ url: "getSalary_Grade.php?sgid=",
parent: "#position",
selected_value: '178'
});
$("#salary").jCombo({ url: "getSalary.php?salaryid=",
parent: "#salary_grade",
selected_value: '630'
});
});
</script>
</body>
</html>

获取位置.php:

<?php

// Connect Database
mysql_connect("localhost","root","");
mysql_select_db("test");

// Execute Query in the right order
//(value,text)
$query = "SELECT tcode, position FROM positions";
$result = mysql_query($query);
$items = array();
if($result && mysql_num_rows($result)>0) {
while($row = mysql_fetch_array($result)) {
$option = array("id" => $row[0], "value" => htmlentities($row[1]));
$items[] = $option;
}
}
mysql_close();
$data = json_encode($items);
// convert into JSON format and print
$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data;
echo $data;
?>

getSalary_Grade.php:

<?php

// Connect Database
mysql_connect("localhost","root","");
mysql_select_db("test");

// Get parameters from Array
$sgid = !empty($_GET['tcode'])
?intval($_GET['tcode']):0;

// if there is no city selected by GET, fetch all rows
$query = "SELECT id,salary FROM salary_grades WHERE salary_grades.id = '$sgid'";

// fetch the results
$result = mysql_query($query);
$items = array();
if($result && mysql_num_rows($result)>0) {
while($row = mysql_fetch_array($result)) {
$option = array("id" => $row[0], "value" => htmlentities($row[1]));
$items[] = $option;
}
}
mysql_close();
$data = json_encode($items);
$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data;
$cache->finish($response);
?>

getSalary.php:

<?php

// Connect Database
mysql_connect("localhost","root","");
mysql_select_db("test");

// Get parameters from Array
$salaryid = !empty($_GET['id'])
?intval($_GET['id']):0;

// if there is no city selected by GET, fetch all rows
$query = "SELECT id,salary FROM salarys WHERE salarys.id = '$salaryid'";

// fetch the results
$result = mysql_query($query);
$items = array();
if($result && mysql_num_rows($result)>0) {
while($row = mysql_fetch_array($result)) {
$option = array("id" => $row[0], "value" => htmlentities($row[1]));
$items[] = $option;
}
}
mysql_close();
$data = json_encode($items);
$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data;
$cache->finish($response);
?>

最佳答案

这应该有效:

getSalary.php

// Connect Database 
mysql_connect("localhost","root","");
mysql_select_db("klayton");

// Get parameters from Array
$salaryid = !empty($_GET['salaryid'])
?intval($_GET['salaryid']):0;

// if there is no city selected by GET, fetch all rows
$query = "SELECT id,salary FROM salarys WHERE id = $salaryid";

// fetch the results
$result = mysql_query($query);
$items = array();
if($result && mysql_num_rows($result)>0) {
while($row = mysql_fetch_array($result)) {
$option = array("id" => $row['id'], "value" => htmlentities($row['salary']));
$items[] = $option;
}
}

getSalary_Grades.php

<?php 

// Connect Database
mysql_connect("localhost","root","");
mysql_select_db("klayton");

// Get parameters from Array
$sgid = !empty($_GET['sgid'])
?intval($_GET['sgid']):0;

// if there is no city selected by GET, fetch all rows
$query = "SELECT id, salary FROM salary_grades WHERE id = $sgid";

// fetch the results
$result = mysql_query($query);
$items = array();
if($result && mysql_num_rows($result)>0) {
while($row = mysql_fetch_array($result)) {
$option = array("id" => $row['id'], "value" => htmlentities($row['salary']));
$items[] = $option;
}
}

关于javascript - 使用 JCombo 制作链式组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21752534/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com