0
我有一个iframe,其src文件(下面给出)包含使用_self目标的表单。该操作返回一个文本字符串。提交后,如果鼠标离开表单或用户类型ESC,我想重新加载带有原始内容的iframe。无法重置iframe内容
我无法获得iframe来重置自身。任何帮助赞赏。这是 '主' 的html文件:
<html>
<head>
<title>iframe test</title>
<script type="text/javascript" src="../jquery-1.11.1.js"></script>
<script>
function foo(e){
$('iframe.popup').css('display','block');
$(e.target).css('z-index','10');
}
$(document).ready(function(){
var popup = $(document).find(".popup");
popup[0].origSrc = popup[0].src; // save orignal content of iframe
$(document).keyup(function(e) {
if (//e.keyCode == 13 || // enter
e.keyCode == 27) { // esc
$(document).find(".popup").hide();
}
});
$(".floatbar").click(function(e){
if (e.target.className == "floatbar"){
e.preventDefault();
}
else {
return true;
}
popup = $(this).find(".popup");
popup.empty();
popup.load(popup[0].origSrc);
popup.show();//fadeIn("slow");
popup.mouseleave(function(e){
//$(this).fadeOut("fast");
$(this).hide();
$(this).empty();
});
popup.keydown(function(e){
if (e.keyCode == 27){
$(this).hide();
$(this).empty();
}
});
});
});
</script>
<style>
.popup {
position:absolute;
border:1em;
top:0px;
font-size: 2.0em;
display:none;
text-decoration: none;
z-index: 5;
}
iframe.login {
background: darkblue;
width: 300%;
min-height:400px;
}
form {
color: white;
list-style-type: none;
}
</style>
</head>
<body>
<a class="floatbar" href="#">Some text
<iframe class="popup login" src="register.close.html"></iframe>
</a>
</body> </html>
文件 'register.close.html':再次
<html>
<head>
</head>
<body>
<form name="registration" action="../php/register.php" method="post"
accept-charset="utf-8" target="_self" >
<div>
<p><label for="submit"> Hi</label>
<input type="submit" name="submit" id="submit" value="Register" >
</p>
</div>
</form>
</body> </html>
感谢。
难道你不能只用'$(“#iframe”)。attr(“src”,$(“#iframe”)。attr(“src”));' – 2014-11-05 00:05:23
iframe重新加载iframe, 。谢谢。仍然困惑为什么加载不起作用。有什么想法吗? – LenB 2014-11-05 10:14:13
我不知道为什么加载不起作用。然而在编程时我喜欢遵循一个简单的规则:KISS,保持简单愚蠢。相当多,不要做任何比它更复杂的事情。 – 2014-11-05 11:27:44