JavaScript 函数 - 更改 DIV 中的内容
我有一个问题。我有这个功能:
function isDone()
{
if(isDone){
$("#loadingStatus").html("NOT DONE...");
}else{
$("#loadingStatus").html("#isDone");
}
}
上面的代码不起作用。上面的代码检查 iFrame 中的内容是否已完成加载。
我想要的是有一个 div 表示如果未加载“未完成...”,但如果已加载,则将另一个 DIV 输出到 #loadingStatus div 中。
更新:
这是我的 100% 代码。
<?php
$key = $_GET['key'];
$s=mysql_query("SELECT * FROM advertisements WHERE `key`='$key'")
or die(mysql_error());
$r=mysql_fetch_assoc($s);
?>
<script type="text/javascript" src="../divided/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../dream/js/iframeLoad.js"></script>
<script type="text/javascript">
function isDone()
{
if(isDone){
$("#loadingStatus").html("Waiting for your advertisements to load...");
}else{
$("#loadingStatus").html($("#isDone").html());
}
}
</script>
</head>
<div style="height:10%">
<table style="border:black;">
<tr>
<td><img src="../dream/images/logo.png"></td>
<td><div id="loadingStatus"></div></td>
<td>3</td>
</tr>
</table>
<div id="isDone" style="display:none">
</div>
</div>
<iframe onload="isDone()" src="<?php echo $r['url']; ?>" width="100%" height="90%" scrolling="auto" frameborder="0">
<p>Your browser does not support iframes.</p>
</iframe>
I have a problem. I have this function:
function isDone()
{
if(isDone){
$("#loadingStatus").html("NOT DONE...");
}else{
$("#loadingStatus").html("#isDone");
}
}
The above code does NOT work. The code above is checking if the content in an iFrame is done loading.
What i want is to have a div that says if it is NOT loaded "NOT DONE..." but if it is loaded then output another DIV into the #loadingStatus div.
UPDATE:
This is my 100 % code.
<?php
$key = $_GET['key'];
$s=mysql_query("SELECT * FROM advertisements WHERE `key`='$key'")
or die(mysql_error());
$r=mysql_fetch_assoc($s);
?>
<script type="text/javascript" src="../divided/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../dream/js/iframeLoad.js"></script>
<script type="text/javascript">
function isDone()
{
if(isDone){
$("#loadingStatus").html("Waiting for your advertisements to load...");
}else{
$("#loadingStatus").html($("#isDone").html());
}
}
</script>
</head>
<div style="height:10%">
<table style="border:black;">
<tr>
<td><img src="../dream/images/logo.png"></td>
<td><div id="loadingStatus"></div></td>
<td>3</td>
</tr>
</table>
<div id="isDone" style="display:none">
</div>
</div>
<iframe onload="isDone()" src="<?php echo $r['url']; ?>" width="100%" height="90%" scrolling="auto" frameborder="0">
<p>Your browser does not support iframes.</p>
</iframe>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可能正在寻找:
编辑:在您的代码中,
isDone
是一个函数,而不是一个变量。据我了解,你必须做类似的事情:You might be looking for:
EDIT: In your code,
isDone
is a function, not a variable. From what I understand, you have to do something like:由于在加载 iFrame 之前不会调用该函数,因此不会出现未加载消息。
您需要在
isDone
div 中有一些默认文本。Because the function isn't called until the iFrame is loaded, the not loaded message will not appear.
You need to have some default text in the
isDone
div.http://jsfiddle.net/sMGTU/
http://jsfiddle.net/sMGTU/
好吧,NOTDONE 永远不会出现,因为没有可以计算 true 的
isDone
变量。而且这个逻辑似乎是颠倒的。相反,在加载主文档时设置“未完成”消息,然后在加载 iFrame 文档时将其替换为“完成”消息:
就是这样;这就是您需要的全部 JavaScript。从
iframe
标记中取出那个可怕的onLoad
属性,并给它一个 ID:Well,
NOTDONE
will never appear because there is noisDone
variable that can evaluatetrue
. Also it seems that that logic is reversed.Instead, set the "not done" message when your main document loads, then replace it with the "done" message when the iFrame document loads:
That's it; that's all the Javascript you need. Take that horrid
onLoad
attribute out of youriframe
markup and give the thing an ID:我认为你的问题可能是你有一个名为
isDone
的布尔变量,并且你的函数定义变量名为isDone
,一个这些应该被称为别的东西。I think your problem may be that you have a boolean variable called
isDone
and your function definition variable is calledisDone
, one of these should be called something else.isDone 变量在代码中的哪里设置?你有 iframe 的加载事件处理程序吗?
试试这个
Where is isDone variable set in the code? Do you have any load event handler for iframe?
Try this
如果你想创建一个新的div:
如果你想从其他地方移动一个div:
如果你想从其他地方复制一个div:
如果你想移动一个元素的内容:
如果你想复制以下内容一个元素:
更新:
查看代码的其余部分揭示了它的更多问题。由于您没有任何变量来确定内容是否已加载,并且只有在内容加载后才调用该函数,因此只需将更改内容的代码放在函数中即可。将初始消息直接放入元素中。
If you want to create a new div:
If you want to move a div from somewhere else:
If you want to copy a div from somewhere else:
If you want to move the contents of an element:
If you want to copy the contents of an element:
Update:
Seeing the rest of the code reveals some more problems with it. As you don't have any variable that determines if the content has loaded or not, and only call the function once the content is loaded, just put the code for changing the content in the function. Put the initial message directly in the element.