js怎样获取父类div的id解决思路
3个回答
展开全部
有一个div,动态用js给div添加了一张表,现在点击table中的某一个td时,想要把这个div的id读出来~
请问有什么方法可以实现的?
HTML code
<div id="faceContainer" style='position: absolute;height: 150px;width: 300px;left: 27px;top: 100px;display:none;border: 1px solid #999999;'></div>
function loadFace()
{
face = document.getElementById("faceContainer");
var strTable = "<table border= \"1\" cellpadding=\"0\" cellspacing=\"0\">";
var i,j,count;
count = 0;
for(i=0;i<7;i++)
{
strTable += "<tr>";
for(j=0;j<14;j++)
{
if(count <=95)
{
strTable += "<td><img src='Face/" + count + ".gif' onclick=\"insertFace('"+count+"')\" alt=\"表情"+count+"\"/></td>";
}
else
{
strTable += "<td> </td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
face.innerHTML = strTable;
}
在线等高手指点`
------解决方案--------------------
HTML code
<div id="faceContainer" style='position: absolute;height: 150px;width: 300px;left: 27px;top: 100px;display:none;border: 1px solid #999999;'></div>
function loadFace()
{
face = document.getElementById("faceContainer");
[color=#FF0000]var tbID="myTable";[/color]
var strTable = "<table id=\""+myTable+"\" border= \"1\" cellpadding=\"0\" cellspacing=\"0\">";
var i,j,count;
count = 0;
for(i=0;i<7;i++)
{
strTable += "<tr>";
for(j=0;j<14;j++)
{
if(count <=95)
{
[color=#FF0000]strTable += "<td><img src='Face/" + count + ".gif' onclick=\"insertFace('"+count+"','"+tbID+"')\" alt=\"表情"+count+"\"/></td>";[/color] }
else
{
strTable += "<td> </td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
face.innerHTML = strTable;
}
------解决方案--------------------
HTML code
<div id="faceContainer" style='position: absolute;height: 150px;width: 300px;left: 27px;top: 100px;display:block;border: 1px solid #999999;'></div>
<script>
window.onload=function(){loadFace();};
function loadFace()
{
var face = document.getElementById("faceContainer");
var strTable = "<table border= '1' cellpadding='0' cellspacing='0'>";
var i,j,count;
count = 0;
for(i=0;i<7;i++)
{
strTable += "<tr>";
for(j=0;j<14;j++)
{
if(count <=95)
{
strTable += "<td><img src='Face/" + count + ".gif' onclick='insertFace("+face.id+")' alt='表情"+count+"'/></td>";
}
else
{
strTable += "<td> </td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
face.innerHTML = strTable;
}
function insertFace(face){
alert(face.id);
}
</script>
------解决方案--------------------
<div id="faceContainer" style='position: absolute;height: 150px;width: 300px;left: 27px;top: 100px;display:block;border: 1px solid #999999;'></div>
<script>
window.onload=function(){loadFace();};
function loadFace()
{
var face = document.getElementById("faceContainer");
var strTable = "<table border= '1' cellpadding='0' cellspacing='0'>";
var i,j,count;
count = 0;
for(i=0;i<7;i++)
{
strTable += "<tr>";
for(j=0;j<14;j++)
{
if(count <=95)
{
strTable += "<td><img src='Face/" + count + ".gif' onclick='getFace(this)' alt='表情"+count+"'/></td>";
}
else
{
strTable += "<td> </td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
face.innerHTML = strTable;
}
function insertFace(face){
alert(face.parentNode.parentNode.parentNode.id);
}
</script>
------解决方案--------------------
在jquery中非常的简单,一般是$("#id").parent().attr("id"); 就可以了
(转载)
请问有什么方法可以实现的?
HTML code
<div id="faceContainer" style='position: absolute;height: 150px;width: 300px;left: 27px;top: 100px;display:none;border: 1px solid #999999;'></div>
function loadFace()
{
face = document.getElementById("faceContainer");
var strTable = "<table border= \"1\" cellpadding=\"0\" cellspacing=\"0\">";
var i,j,count;
count = 0;
for(i=0;i<7;i++)
{
strTable += "<tr>";
for(j=0;j<14;j++)
{
if(count <=95)
{
strTable += "<td><img src='Face/" + count + ".gif' onclick=\"insertFace('"+count+"')\" alt=\"表情"+count+"\"/></td>";
}
else
{
strTable += "<td> </td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
face.innerHTML = strTable;
}
在线等高手指点`
------解决方案--------------------
HTML code
<div id="faceContainer" style='position: absolute;height: 150px;width: 300px;left: 27px;top: 100px;display:none;border: 1px solid #999999;'></div>
function loadFace()
{
face = document.getElementById("faceContainer");
[color=#FF0000]var tbID="myTable";[/color]
var strTable = "<table id=\""+myTable+"\" border= \"1\" cellpadding=\"0\" cellspacing=\"0\">";
var i,j,count;
count = 0;
for(i=0;i<7;i++)
{
strTable += "<tr>";
for(j=0;j<14;j++)
{
if(count <=95)
{
[color=#FF0000]strTable += "<td><img src='Face/" + count + ".gif' onclick=\"insertFace('"+count+"','"+tbID+"')\" alt=\"表情"+count+"\"/></td>";[/color] }
else
{
strTable += "<td> </td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
face.innerHTML = strTable;
}
------解决方案--------------------
HTML code
<div id="faceContainer" style='position: absolute;height: 150px;width: 300px;left: 27px;top: 100px;display:block;border: 1px solid #999999;'></div>
<script>
window.onload=function(){loadFace();};
function loadFace()
{
var face = document.getElementById("faceContainer");
var strTable = "<table border= '1' cellpadding='0' cellspacing='0'>";
var i,j,count;
count = 0;
for(i=0;i<7;i++)
{
strTable += "<tr>";
for(j=0;j<14;j++)
{
if(count <=95)
{
strTable += "<td><img src='Face/" + count + ".gif' onclick='insertFace("+face.id+")' alt='表情"+count+"'/></td>";
}
else
{
strTable += "<td> </td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
face.innerHTML = strTable;
}
function insertFace(face){
alert(face.id);
}
</script>
------解决方案--------------------
<div id="faceContainer" style='position: absolute;height: 150px;width: 300px;left: 27px;top: 100px;display:block;border: 1px solid #999999;'></div>
<script>
window.onload=function(){loadFace();};
function loadFace()
{
var face = document.getElementById("faceContainer");
var strTable = "<table border= '1' cellpadding='0' cellspacing='0'>";
var i,j,count;
count = 0;
for(i=0;i<7;i++)
{
strTable += "<tr>";
for(j=0;j<14;j++)
{
if(count <=95)
{
strTable += "<td><img src='Face/" + count + ".gif' onclick='getFace(this)' alt='表情"+count+"'/></td>";
}
else
{
strTable += "<td> </td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
face.innerHTML = strTable;
}
function insertFace(face){
alert(face.parentNode.parentNode.parentNode.id);
}
</script>
------解决方案--------------------
在jquery中非常的简单,一般是$("#id").parent().attr("id"); 就可以了
(转载)
展开全部
动态用js给div添加了一张表,现在点击table中的某一个td时,要把这个div的id读出来。
$("#floatDiv").before("<div class=\"floatDiv\" id=\"floadDiv"+peo.value+"\"><div class=\"selectDiv\">"+peo.nextSibling.innerText+"</div><div class=\"selectCancle\"><a href=\"javascript:closeDiv(this)\">×</a></div></div>");
}else if(!peo.checked){
var divID ="floatDiv"+peo.value;
$("#"+divID).remove();
}
}
$("#floatDiv").before("<div class=\"floatDiv\" id=\"floadDiv"+peo.value+"\"><div class=\"selectDiv\">"+peo.nextSibling.innerText+"</div><div class=\"selectCancle\"><a href=\"javascript:closeDiv(this)\">×</a></div></div>");
}else if(!peo.checked){
var divID ="floatDiv"+peo.value;
$("#"+divID).remove();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$(this).parent().attr('id');
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询