我有一个家谱和下拉列表也有父母和孩子的所有名称,每个孩子里面都有链接,我想当我点击任何子链接时显示他的父亲在下拉列表中(选择该选项)。请有人帮助我。
这是显示孩子的功能
function getChild($family_tree,$parent){
$list = "<ul style='list-style-type:none'>";
foreach($family_tree[$parent] as $each_child){
$list .= "<li>" . $each_child[0]." "."<a style='text-decoration:none ; font-size: smaller' onclick='changeParent()' href='#'>".'Change parent'."</a>";
if(isset($family_tree[$each_child[1]])){
$list .= getChild($family_tree,$each_child[1]);
}
$list .= "</li>";
}
$list .= "</ul>";
return $list;
}
这个函数来得到孩子的父亲
public function getParentId($childId)
{
$statment = $this->db->prepare("SELECT parent FROM `person` WHERE id = $childId");
$statment->execute();
$result = $statment->fetchAll();
foreach($result as $output){
return $output['parent'];
}
}
这是我的表格
<form method="post">
Child Name: <input type ='text' name ='name' placeholder="Enter name here">
<select name="parent" id="names" onchange="getSelectValueId()">
<option>--Select Parent--</option>
<option><?php echo $object->displayParent()?></option>
</select>
<br>
<input type="submit" name="submit" value="Enter">
</form>
&#13;
更新 **** 现在,当我点击链接时,我得到了孩子的身份证,我的功能是获得父ID ...我怎么能改变现在选择的选项?任何人都可以帮助我PLZ !!!!
这是函数从链接
获取子ID
function changeParent(){
$(document).ready(function(){
$("a").click(function() {
function getEventTarget(e) {
e = e || window.event;
return e.target || e.srcElement;
}
var ul = document.getElementsByClassName('listSet');
[].forEach.call(ul, function(el) {
el.onclick = function(event) {
var target = getEventTarget(event);
alert(target.id);
};
});
});
});
}
&#13;
答案 0 :(得分:0)
我解决了它:)))这是答案但是我用out函数解决了它,得到了父id:/
function changeParent(){
$(document).ready(function(){
$("a").click(function() {
function getEventTarget(e) {
e = e || window.event;
return e.target || e.srcElement;
}
var ul = document.getElementsByClassName('listSet');
[].forEach.call(ul, function(el) {
el.onclick = function(event) {
var target = getEventTarget(event);
//alert(target.id);
document.getElementById('names').value=target.id; //This line to change selected option to parent of child clicked.
};
});
});
});
}
&#13;