我有这3个div
当您点击那个孩子的孩子时,是否可以获取ID <?php
$serverName = "serverName\\sqlexpress"; //serverName\instanceName
$connectionInfo = array( "Database"=>"epromis_test", "UID"=>"php_test", "PWD"=>"phptest&commat123");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
,如果可以,怎么办?
parent
function getParentId(el) {
//get the id "parent"
}
答案 0 :(得分:1)
您可以使用Node.parentNode
:
function getParentId(el){
var p = el.parentNode.parentNode;
console.log(p.id);
}
<div id="parent">
<div class="child">
<div class="child-of-child" onClick="getParentId(this)">
<!-- some code here -->
Click
</div>
</div>
</div>
答案 1 :(得分:1)
您可以在点击功能内使用el.parentElement
:
function getParentId(el){
var id = el.parentElement.parentElement.id;
console.log(id);
}
<div id="parent">
<div class="child">
<div class="child-of-child" onClick="getParentId(this)">
click
</div>
</div>
</div>