[html]
这个是主页面
<%@ page language="java" import="java.util.*;" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/jquery_last.js"></script>
<script type="text/javascript" src="scripts/ui.core.js"></script>
<script type="text/javascript" src="scripts/ui.dialog.js"></script> <title>Luther's List - Info</title>
<script type="text/javascript">
jQuery.noConflict();
jQuery(function(){
jQuery("#btn").click(
function(){
var params = '';
params = jQuery("#tellFriendsForm").serialize();
var ps = jQuery(window.frames["myRecaptcha"].document.getElementById("recaptcha")).serialize();
params += '&' + ps;
jQuery("#layer-email").dialog('close');
jQuery.ajax({
url : "dealOperate_tellFriendsViaAjax.do",
type: 'get',
dataType: 'html',
data: params,
error: asyncResponse,
success: asyncResponse
});
}
);
function asyncResponse(data) {
if(data == '1'){/*send email successful*/
jQuery("#email-sent").dialog('open');
jQuery(".ui-dialog-titlebar").hide();
}else{
jQuery("#layer-email").dialog('open');
jQuery(".ui-dialog-titlebar").hide();
jQuery("#errorMsg").html(data);
}
};
/* tell a friends dialog*/
jQuery("#email-sent").dialog({
bgiframe: true,
resizable: false,
autoOpen: false,
width: 400,
closeOnEscape: false,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
}
});
/* tell a friends dialog*/
jQuery("#layer-email").dialog({
bgiframe: true,
resizable: false,
autoOpen: false,
width: 400,
closeOnEscape: false,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
}
});
jQuery("#openDialog").click(
function(){
jQuery("#layer-email").dialog('open');
jQuery(".ui-dialog-titlebar").hide();
jQuery("#errorMsg").html("");
}
);
});
</script>
</head>
<body>
<a id="openDialog" href="javascript:void(0)"> Tell A friend! </a>
<div id="email-sent">
<h1>Email Sent</h1>
<div class="inner">
<h2 id="title">Cream Disco Dot Diaper Bag</h2>
<fieldset>
The deal has been emailed to your friend(s). Click <br/>the Close button below to continue.
<p align="center">
<input class="cancel" type="button" onclick="jQuery('#email-sent').dialog('close');" value="" style="cursor: pointer;"/>
</p>
</fieldset>
</div>
</div>
<div id="layer-email">
<h1>Email to a Friend</h1>
<div class="inner">
<h2 id="title">Cream Disco Dot Diaper Bag</h2>
<s:form id="tellFriendsForm" theme="simple">
<input type="text" name="id" value="xx" />
<iframe id="myRecaptcha" name="myRecaptcha" frameborder="0" width="320px" height="90px" SRC="http://localhost:8080/lutherslist/recaptcha.jsp"></iframe>
<input type="button" value="Sent" style="cursor:pointer" id="btn"/> <input type="button" style="cursor:pointer" value="Cancel" onclick="jQuery('#layer-email').dialog('close');" /></p>
</s:form>
</div>
</div>
</body>
</html>下面是 recaptcha.jsp<%@ page language="java" import="java.util.*;" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Luther's List - Info</title>
<script type="text/javascript" src="scripts/jquery_last.js"></script>
</head>
<body>
<script>
var RecaptchaOptions = {
theme: 'custom',
lang: 'en',
custom_theme_widget: 'recaptcha_widget'
};
</script>
<form name="recaptcha" id="recaptcha">
<div id="recaptcha_image" class="recaptcha_image" title="Change" onclick="Recaptcha.reload();" style="cursor:pointer"></div>
<div style="text-align:left;width:300px;padding-top:5px"> <input type="text" style="border:1px solid #D1E4F3" id="recaptcha_response_field" name="recaptcha_response_field"/></div>
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LfYHgcAAAAAAN7qG6KFz0VUbNeuHNhg1PDuDFMB&lang=en"></script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=6LfYHgcAAAAAAN7qG6KFz0VUbNeuHNhg1PDuDFMB=en" frameborder="0"></iframe><br />
<textarea name="recaptcha_challenge_field"></textarea>
</noscript>
</form>
</body>
</html>[/html]
当第一次提交的时候,能够成功取到 iframe 中字段的值, 第二次的时候就取不到了,
报错如下: window.frames.myRecahtcha.document is null有劳各位指教...
这个是主页面
<%@ page language="java" import="java.util.*;" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/jquery_last.js"></script>
<script type="text/javascript" src="scripts/ui.core.js"></script>
<script type="text/javascript" src="scripts/ui.dialog.js"></script> <title>Luther's List - Info</title>
<script type="text/javascript">
jQuery.noConflict();
jQuery(function(){
jQuery("#btn").click(
function(){
var params = '';
params = jQuery("#tellFriendsForm").serialize();
var ps = jQuery(window.frames["myRecaptcha"].document.getElementById("recaptcha")).serialize();
params += '&' + ps;
jQuery("#layer-email").dialog('close');
jQuery.ajax({
url : "dealOperate_tellFriendsViaAjax.do",
type: 'get',
dataType: 'html',
data: params,
error: asyncResponse,
success: asyncResponse
});
}
);
function asyncResponse(data) {
if(data == '1'){/*send email successful*/
jQuery("#email-sent").dialog('open');
jQuery(".ui-dialog-titlebar").hide();
}else{
jQuery("#layer-email").dialog('open');
jQuery(".ui-dialog-titlebar").hide();
jQuery("#errorMsg").html(data);
}
};
/* tell a friends dialog*/
jQuery("#email-sent").dialog({
bgiframe: true,
resizable: false,
autoOpen: false,
width: 400,
closeOnEscape: false,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
}
});
/* tell a friends dialog*/
jQuery("#layer-email").dialog({
bgiframe: true,
resizable: false,
autoOpen: false,
width: 400,
closeOnEscape: false,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
}
});
jQuery("#openDialog").click(
function(){
jQuery("#layer-email").dialog('open');
jQuery(".ui-dialog-titlebar").hide();
jQuery("#errorMsg").html("");
}
);
});
</script>
</head>
<body>
<a id="openDialog" href="javascript:void(0)"> Tell A friend! </a>
<div id="email-sent">
<h1>Email Sent</h1>
<div class="inner">
<h2 id="title">Cream Disco Dot Diaper Bag</h2>
<fieldset>
The deal has been emailed to your friend(s). Click <br/>the Close button below to continue.
<p align="center">
<input class="cancel" type="button" onclick="jQuery('#email-sent').dialog('close');" value="" style="cursor: pointer;"/>
</p>
</fieldset>
</div>
</div>
<div id="layer-email">
<h1>Email to a Friend</h1>
<div class="inner">
<h2 id="title">Cream Disco Dot Diaper Bag</h2>
<s:form id="tellFriendsForm" theme="simple">
<input type="text" name="id" value="xx" />
<iframe id="myRecaptcha" name="myRecaptcha" frameborder="0" width="320px" height="90px" SRC="http://localhost:8080/lutherslist/recaptcha.jsp"></iframe>
<input type="button" value="Sent" style="cursor:pointer" id="btn"/> <input type="button" style="cursor:pointer" value="Cancel" onclick="jQuery('#layer-email').dialog('close');" /></p>
</s:form>
</div>
</div>
</body>
</html>下面是 recaptcha.jsp<%@ page language="java" import="java.util.*;" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Luther's List - Info</title>
<script type="text/javascript" src="scripts/jquery_last.js"></script>
</head>
<body>
<script>
var RecaptchaOptions = {
theme: 'custom',
lang: 'en',
custom_theme_widget: 'recaptcha_widget'
};
</script>
<form name="recaptcha" id="recaptcha">
<div id="recaptcha_image" class="recaptcha_image" title="Change" onclick="Recaptcha.reload();" style="cursor:pointer"></div>
<div style="text-align:left;width:300px;padding-top:5px"> <input type="text" style="border:1px solid #D1E4F3" id="recaptcha_response_field" name="recaptcha_response_field"/></div>
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LfYHgcAAAAAAN7qG6KFz0VUbNeuHNhg1PDuDFMB&lang=en"></script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=6LfYHgcAAAAAAN7qG6KFz0VUbNeuHNhg1PDuDFMB=en" frameborder="0"></iframe><br />
<textarea name="recaptcha_challenge_field"></textarea>
</noscript>
</form>
</body>
</html>[/html]
当第一次提交的时候,能够成功取到 iframe 中字段的值, 第二次的时候就取不到了,
报错如下: window.frames.myRecahtcha.document is null有劳各位指教...
你的iframe在初始的时候不能有src为某某页面,如果你用到了,就不能用表单提交,必须用
ifrid.src=location
如果你非得用表单的方式处理,你的iframe标签就不能有src,即
<iframe width=100 height=100 id=ifrid></iframe>注意此时没有src,你在提交的时候才可以正确的获得值