JS获取iframe 里面div的内容:
alert(documentgetElementById("iframe的id")contentWindowdocumentgetElementById("div的id")innerHTML);
这行代码绝对兼容任何浏览器,如有疑问,请直接联系本人!
运行这行代码必须保证iframe的url和主页面的url的主域名必须一致,否则无效
有一个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 = documentgetElementById("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>";
faceinnerHTML = 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 = documentgetElementById("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>";
faceinnerHTML = 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>
windowonload=function(){loadFace();};
function loadFace()
{
var face = documentgetElementById("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("+faceid+")' alt='表情"+count+"'/></td>";
}
else
{
strTable += "<td> </td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
faceinnerHTML = strTable;
}
function insertFace(face){
alert(faceid);
}
</script>
------解决方案--------------------
<div id="faceContainer" style='position: absolute;height: 150px;width: 300px;left: 27px;top: 100px;display:block;border: 1px solid #999999;'></div>
<script>
windowonload=function(){loadFace();};
function loadFace()
{
var face = documentgetElementById("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>";
faceinnerHTML = strTable;
}
function insertFace(face){
alert(faceparentNodeparentNodeparentNodeid);
}
</script>
------解决方案--------------------
在jquery中非常的简单,一般是$("#id")parent()attr("id"); 就可以了
(转载)
以上就是关于如何通过JS获取iframe 里面div的id值全部的内容,包括:如何通过JS获取iframe 里面div的id值、js怎样获取父类div的id解决思路、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)