【发布时间】:2015-06-11 09:06:46
【问题描述】:
我正在尝试根据访问者的年龄显示不同的 iframe,而无需重定向/刷新。
但是在验证访问者年龄后,javascript 没有被正确应用,或者根本没有。
我总是以一个空白的 iframe 结束。 有人请看我下面的代码:
<html>
<head><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script></head>
<form method="post">
<input type="date" name="dob"><br>
<input type="submit" name="submit" value="Verify Age" />
</form>
<?php
$minAge = 18; // You might read this from a file/database.
$minAge *= 3600*24*365.25; // $minAge in seconds
if(isset($_POST['submit'])){
$birth_date = strtotime($_POST['dob']);
$now = strtotime("now");
$age = $now - $birth_date; // age is in seconds
if($age > $minAge)
echo '<script>$("#myiframe").attr("src", "http://URL1.com");</script>';
else
echo '<script>$("#myiframe").attr("src", "http://URL2.com");</script>';
} ?>
<iframe id="myiframe"></iframe>
</html>
【问题讨论】:
-
等等...如果你用 PHP 做这个,你需要 PHP 做什么?为什么不只是
echo '<iframe src="http://URL1.com"></iframe>';?
标签: javascript php jquery html iframe