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