我对JS不太好,我一直在寻找一个小时,但找不到我可以改变工作的解决方案。 在我的父框架中,我有这个
<input type="hidden" name="starter_name_available" id="starter_name_available">
在我的iFrame中我有
$starter_name_available = "0";
(0
可能是不同的值,具体取决于来自父级的输入)
现在,当用户输入父级的某些详细信息时,iFrame会刷新,这会确定$starter_name_available
的值以及其他内容,如何将$starter_name_available
的值传递给它的父级?在iframe上没有任何东西可以互动。
我无法让iFrame与JS Fiddle合作,所以这里有更多的代码来帮助理解:
父javascript:
function SLTUpdateIframe()
{
var first = document.getElementById("starter_first").value;
if (first == ""){
first = "xxx";
}
var concatString = "";
var url = concatString.concat("newcall/SLT/sltusercount.php?first=", first, "&last=", last);
document.getElementById('SLTiframe').src = url;
}
父html:
<iframe src="newcall/SLT/sltusercount.php?first=xxx&last=xxx" name="SLTiframe" id="SLTiframe" seamless width="650px" height="45px" scrolling="no" frameborder="0"></iframe>
<label for="starter_first" class="label">First name</label><br />
<input type="text" class="textbox" name="starter_first" id="starter_first" onkeyup="SLTUpdateIframe()" />
<input type="hidden" name="starter_name_available" id="starter_name_available">
iframe代码:
<html>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<?
$first = "xxx";
if(isset($_GET['first'])){
$first = strtolower($_GET['first']);
}
$last = "xxx";
if(isset($_GET['last'])){
$last = strtolower($_GET['last']);
}
$account = ">".$first.".".$last."@";
//the > and the @ surrounding the name are there to ensure we are finding the whole name and not just a fragment
// for example if we search Joe.Blo it shouldn't respond that it's found that account because Joe.Bloggs exists
$userlist = file_get_contents('../../lists/aduserlist.php');
$userlist = strtolower($userlist);
if(strpos($userlist,$account) !== false) {
if(!($account == '>xxx.xxx@')){
$first = ucfirst(strtolower($first));
$last = ucfirst(strtolower($last));
$account = $first.".".$last;
echo("<font face='Verdana' color='#303030' size='3'>There is already a user account with the name ".$account." </font>");
echo("<font face='Verdana' color='#f56a00' size='2'><br>Please try a different name (e.g. Steven to Steve) or add a number (e.g. John Smith2)</font>");
$starter_name_available = "0";
}
}else{
if(!($account == '>xxx.xxx@')){
$first = ucfirst(strtolower($first));
$last = ucfirst(strtolower($last));
$account = $first.".".$last;
echo("<font face='Verdana' color='#303030' size='3'>The name ".$account." is available</font>");
$starter_name_available = "1";
}
}
?>
</body>
</head>
答案 0 :(得分:0)
想通了,最后,感谢那些看了看的人,我在if / else语句中的iframe中添加了这一行(改变了每个中的val)
echo("<script>$(document).ready(function(){ $('#starter_name_available', window.parent.document).val('1');});</script>");